Loading
Unit testing is a crucial activity for every modern software project. However, writing and maintaining code for unit tests is one of the most annoying activities in software engineering. So, why are you still doing it? Actually, modern unit testing tools allow the automated generation of test code based on some higher-level specifications, that can be even entered via a graphical user interface. in this article, i give you three reasons why you should use these tools.
General-Purpose Programming Languages are (obviously) not optimized for writing unit test code. This means that when you write your test code in a language like C#, Java, or Python, you have to write a lot of code over and over again, although this code is the same or at least similar for many of your tests. Why? Obviously, these languages are made for expressing any kind of functionality and structure with them (that’s why they are also called general-purpose programming languages). In unit testing however, you always write the same kind of code. Every unit test requires the same information- A code unit that has to be tested- Input data for this code unit – Assertions that have to be ensured on the output returned by the code unit when feeding it with the input dataUsing visual interfaces instead of general-purpose programming languages, you can simply focus on these main components of your test cases, and optimize the interface for specifying them. In a next step, the code required to run these test cases can be generated automatically (by creating code templates that are filles with the – this is refered to as model-driven engineering)
When creating unit tests by hand, a lot of effort is put into writing code for each unit test (as described in detail above). However, every change in the tested software usually breaks some amount of test cases. The unit test code has to be repaired, so that it builds, and also tests the code unit correclty. As a result, maintaining these test cases can actually take more time than creating them. The biggest problem here is that most developers do not really care about structuring their unit test code, or know about best-practice patterns for unit testing. As a result, adapting code, especially several weeks or months after it has been written, becomes a real burden. Unit test code that is generated from some higher-level specification however automatically sticks to best practices for readability and maintainability.
Besides efficient code generation, modern unit testing tools usually offer graphical interfaces for managing your test cases. These graphical interfaces enforce you to stick to a certain structure when creating and adapting unit tests. This structure is defined to effectively and efficiently guide you through the unit testing process, making sure that you do not waste time at any point. As a result, it is also easy to adapt and understand created tests, even years after they have been created.These are my main reasons why you should stop writing unit test code. Do you agree with them? Do you have even better reasons? What is your personal take on test code generation? Let me know in the comments 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.
Daniel Lehner