Home > Articles > Programming > Java

  • Print
  • + Share This
Like this article? We recommend

Key Requirements

What are some of the key requirements that you want from a unit testing framework? First, you want to write tests with a few lines of code without taking too much time away from the actual coding. Even if most of us want to be able to write exhaustive tests while developing our code, the need to become more and more "productive" leads to less and less testing. In fact, the fewer tests we write, the more brittle our code is and consequently the productivity goes down because more time is spent debugging the code.

Secondly, you want to be able to look at the results of the tests without having to manually sift through a large amount of output. We often use debugging as an approach to testing, so we can put different expressions in the debugger to check for anomalies in behavior when the program is running. Or we may resort to the standard System.out.println statements to do our debugging. But both of these methods require us to pay close attention to the output and cannot necessarily be expressed in the binary terms of pass/fail.

You may also want to break the tests into a logical hierarchy of tests while having the ability to assemble a collection of individual tests very easily into a test suite. It should be possible for anyone other than the original developer to be able to execute the tests and interpret the results or combine the tests from various developers and run them together without any anxiety about how and when things would break. Above all, it should be easy to write the tests and modify them at any time. These are all the objectives for which JUnit framework has been established. Using JUnit, you incrementally build a test suite that will help you establish well-defined milestones in your development process and spot unintended "undocumented features."

  • + Share This
  • 🔖 Save To Your Account