Although unit testing is a valuable activity for every software development project, it’s also a pain in the ass of every developer who has to deal with it. Why? Because defining, writing, and maintaining your tests over time costs a lot of effort, which you could better spend on writing actual code that creates cool new features in your software. But why is that? Because you are still using ad-hoc ways and inefficient tools to manually write unit test code. In this article, I’ll show you 3 features that you should look out for when chosing a developer-friendly unit testing tool.
1Generate Boilerplate Code
Although writing software code is fun and exciting, this is usually not true for unit tests. First of all, test code does not give you new functionality – and from a developers point of view, functionality is of course cooler than quality. But most of all, 80 % unit test code is essentially the same. So unit testing is writing similar code, following the same structure, over and over again.
1) You prepare your data (over and over again, because unit tests should be independent)
2) You execute the unit under test (so if you write 10 tests for 1 method, this is the same code in all of these tests)
3) you do your assertions. But what if I told you that you can have this code generated for you? Simply use the right tool, create your tests in a visual interface, and let tool handle the boilerplate code for you.
2Automate Test Case Definition
Besides writing code, the next annoying task in unit testing is thinking about what to actually test. It takes a lot of brain-wringling to think about ways to destroy your software, and then come up with some meaningful data that brings to code what you have thought out in your mind. With the right methods (they are called equivalence class partitioning and boundary value analysis, and described here: 2 methods that help you save 60 % of your effort in Unit Testing you can save most of your time for thinking about how to test your system, and focus on the most essential part of your job: developing high-quality software. With the right unit testing tool at hand, you don’t even have to worry about these methods any more. Modern unit testing tools incorporate them in their visual interface to guide you through applying them on your code.
3 Automatically Optimize your Test Suite over time
Although defining tests and creating code is definitely annoying, the most effort in unit testing lies in maintenance. Without maintaining your test code, you don’t have to start testing in the first place. Your test suite will soon become a non-executable graveyard of many hours of work, without providing any actual value to your coding. To avoid that, you should make sure to keep your test suite manageable. Therefore, you should regularly check whether you should get rid of some test cases – because the more unit tests you have, the more effort it is to maintain them, and the less likely you are to put in the effort 😉 But although there are some guidelines on how to continuously optimize your test suite (see e.g. 5 Bulletpoints how to spot Bad Unit-Tests), this is still (yet another) pain in the ass. Therefore, one feature you should look out for in your unit testing tool is that it provides you maximum support for this. Tools can e.g. give you information about the efficiency of your test cases, in terms of code coverage or mutation score. They can even recommend test cases that should be deleted based on this information (genetic algorithms have shown to be quite effective here: Search Algorithms for Regression Test Case Prioritization). On top of that, a good unit testing tool also gives you the power to leverage information that you have already defined in your test suite. And no, I’m not talking copy-paste here. Good unit testing tools store find similarities in between your current unit under test and previously tested code, to give you recommendations on what you would like to do next. It’s called recommender systems. So just like netflix is showing you what you should watch next (Netfix Research on Recommendations), you can have your unit testing tool show you which unit tests you should add to your test suite.What is your take on unit testing? How do you think these three features would benefit your personal work routine? Let me know in the comment section below!
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.