D E V M A T E

Loading

vectorjuice Freepik Illustration developer in front of laptop
Especially young software developers tend to develop in a chaotic manner. They do not focus on code quality, architecture or reusability. Why? Because they need their mental capabilities to create working code. Juniors often forget to care about unit testing at all. And if they write unit test, they do not consider the quality of the test code either. This article is about this issue and how you can avoid this problem by following some easy rules. 
 

1.     Use test frameworks and write tests

This point should be obvious, but especially beginners tend to favor console output tests over the use of test frameworks and writing unit tests. If you are familiar with the test framework of your choice, it takes the same time and efforts to write your tests and verify if your code is doing what it’s meant to do, then writing console tests. 
 

2.     Consider the F-I-R-S-T Rules

The F-I-R-S-T rule [1] was created by Robert C. Martin – the clean code guru-  and introduced in his book “Clean Code: A Handbook of Agile Software Craftsmanship”. The acronym defines the requirements a unit test has to satisfy to be considered good quality. 
F – Fast: Unit test have to be fast in execution
I – Independent: Unit test must be independent against each other
R – Repeatable: When you execute a test multiple times the result should not change
S – Self-Validating: No one should have to interpret the result of the test. It should either be positive or negative.
T – Timely: Unit tests should be written before or during the implementation of new features not afterwards. 
 

3.     Use Design-Pattern

The AAA-Pattern[2] is nowadays the industry standard for unit test code. It means that you should structure the code in three sections:
A – Arrange: arrange your test data. Initialize and set your variables and parameters.
A – Act: execute your method under test with the arranged data
A – Assert: Assert the expected outcome of your test. 
 

4.     Consider the coding guidelines of your project

Develop your test code as it is your productive code, use the same standards and have high quality expectations as you would have from other system critical parts of your software. So also apply your coding guidelines to your test code as well. 
 

5.     Use test code generation tools

Good test code generation tools create well-structured test code out of the box. By using such tools, you can focus on the requirements of your test and let the unpleasant work do the generation tool. As a positive byproduct you will save time and money and receive highest quality of test code. 
 

6.     Give your tests meaningful names

Using a test code generation tool doesn’t give your test cases and tests meaningful names. In fact, every code you write is read multiple times but is only written once and edited only a fraction of the times it is read. So meaningful names which describes what is going on and what intention you had is most important. This is something a software engineer has to do manually. No code generation tool can do it automatically.
 

7.     Include unit testing in the review process

Last but not least it is most important that you include your tests in the review process. Your teammates should review your code as well as your test code and give you feedback if there is something misleading or wrong. Good test code generation tools support with that issue because they often provide an UI and are therefore easier to understand. The test code on the other side is less important because it was generated and therefor considers design patterns and coding guidelines. 
 

Summary

You should treat test code and unit tests as part of your software solution and therefor manage it like every other code. If you are using the right tools and have a quality mindset, writing tests becomes a habit and the quality of your code as well as your solution quality increases.
 
Tell me about your thoughts in the comments section below!
 
written by David Theil

[1][2] Robert C. Martin; 2009: Clean Code: A Handbook of Agile Software Craftsmanship. Prentice Hall. USA. 

 

Computer vector created by vectorjuice – www.freepik.com

Leave a Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

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