Jump to content
Mike Torrettinni

Unit testing for beginners

Recommended Posts

8 minutes ago, Mike Torrettinni said:

From all the blogs I read, I didn't come across anything like such a simple explanation.

I don't think it is this simple though

Share this post


Link to post
7 hours ago, Mike Torrettinni said:

From all the blogs I read, I didn't come across anything like such a simple explanation.

 

There are a number of uses for Unit Testing.  Purists have their specific definitions, but it's a tool just like any other.  You choose how to use it.  Now, a hammer has some specific purposes like pounding in nails but you could use a hammer for quite a few more useful things.  

 

My advice is to start small - think of unit tests as simple stop/go signs for your code.  Set a bare minimum functionality for each test.  Then think about what possible abnormal inputs might occur and test for a few of those.  Over time you'll end up with a large number of tests that add value to your operation.  They will guard against you releasing some bugs that you might not have caught before.

 

Once you start feeling comfortable with tests, then other uses arise.  Like you start taking a little more risk - as you rely on your tests to keep you on the right path.  Once you can take more risks, you could potentially make larger leaps forward in functionality.  It's a self-feeding positive cycle.  But in the beginning, add a single test and watch it fail.  Your skill level went up +1.  Now make that one test work and and then watch the test pass.  Skill level +1.   Write a little code and add another test...  eventually write the test before the code is written (I don't do this often but when I have it has saved some time.)

 

 

 

  • Thanks 1

Share this post


Link to post

Any problem can be expanded into something insurmountable if one so likes.
But, if you apply the KISS and Pareto rules- you can at least start out with a less complicated scenario.

  • Like 2

Share this post


Link to post

I also find unit tests are a great way to start getting familiar with foreign code. Like libraries from 3rd parties or your own company. You're new to it, you don't really have a feeling for it yet. So before just straight out using the code in your real life application, why not start with a few unit tests so you know you can trust it for your use cases? Maybe you can even contribute the tests back.

  • Like 2

Share this post


Link to post

OK, first test done successful! 🙂

Things are much clearer now!

 

This video is for real beginners, very easy to follow:

 

 

 

Thanks for the help everybody!

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×