D E V M A T E

Loading

When to write an unit test.

You are here:
Estimated reading time: 1 min

We’ve already established what a unit test is in one of our previous articles. Now it’s time to define when you should write a unit test! A question that is not that easy to answer.

3 approaches of when to write a unit test

  1. If you are an early bird then you probably prefer the Test Driven Development (TDD) approach. You start by writing unit tests first and then write the actual code later.
    One of the biggest advantages of Test Driven Development is that you actually get better quality code since you already take all possible mistakes into account before you implement anything.
  2. However, the most common approach although is to write unit tests during the implementation process. Here you try to develop awesome code while always having the actual testing process in mind. This approach is definitely something for more experienced developers.
  3. Additionally as a developer you are sometimes confronted with the task to maintain legacy code. Legacy code describes code that is no longer supported. Writing unit tests for legacy code is very difficult and cumbersome.

Best practices of unit testing

As we have previously learned creating unit tests is a crucial process in producing quality code. You should either write unit tests early on during the implementation or you should go for the Test Driven Development approach.

Was this article helpful?
Dislike 1
Views: 83

Continue reading

Previous: 5 pitfalls beginners experience when writing their first unit tests.
Next: Bad Unit Tests vs. Good Unit Tests

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

Privacy Settings saved!
Privacy Settings

When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.

GetResponse, Google Analytics

We use Google Analytics for marketing purposes. You can disable these cookies.
  • __utmz
  • __utma
  • _ga
  • _gat

We use GetResponse for marketing purposes. This service cannot be disabled, otherwise the website functions will be limited.

Decline all Services
Accept all Services
Get Free Access Now to
9 eBooks!
All about Automated Software Testing
Proven experts
Learn to save up to 75% of your test efforts
Get Free Access Now!
Get Access Now! & Save 50%
Personal Trainer FREE Nutrition Custom Workout App
Get Access Now!
eBook Download
Enter your details to get your free ebook!
All about Automated Software Testing
Download Free Ebook
SUBSCRIBE
MY WEB
NEWSLETTERS
Lorem ipsum dolor sit amet, consectetur adipiscing