Learn, Share and Keep Learning
| JUnit Introduction |
| Testing Tools - Unit Testing |
|
This article, will explore what is JUnit and how to write simple Unit test cases using JUnit. TestingGeek will also touch upon history of JUnit and will find out how it came into existence.
Automated unit test cases makes your life very easy since you will spend less time in doing debugging and more on writing test and eventually code that will pass those tests. Presence of automated unit testing will make you more confident that your tests are not breaking anything and if something is broken, unit test cases will catch them. Writing test cases in JUnit is not difficult, in fact it is very simple and straight forward to write unit test cases. As mentioned earlier, it is faster to develop code using JUnit since it increases your effectiveness. As a tester, you might not be involved directly in writing JUnit test cases, but you can and should assist developers in writing good Unit test cases and making sure that coverage from unit test cases is proper.JUnit is a unit testing framework for the Java programming language. This framework was developed by Kent Beck and Erich Gamma. JUnit is one of the most successful and widely used xUnit automation framework. Usage of JUnit have increased further with the progress of Xtreme programming and Test Driven Development in particular. As mentioned earlier, It is very simple to write JUnit test cases. Any JUnit class that contain test methods should extend TestCase class. This class now can define any number of testXXX() methods. Validating any functionality of system is implemented with the help of variation of assert methods. This TestCase subclass can also implement setup() and tearDown() functions to initialize and release specific objects that you might need for testing this subclass. This can also be used to ensure that there is no side effect of running test cases. TestCase instances can be composed of TestSuite and instance of TestSuite can invoke all testXXX methods defined in the TestCase. JUnit also comes with two type of Test Runners i.e. textual test runners and graphical test runners. JUnit gives an indication of successful execution in the form of either OK message in textual runner and green bar in graphical runner. As explained earlier, using JUnit is not a rocket science, it is very simple. In order to get started with JUnit, you can follow these steps.
Hope this article gave you good understanding of JUnit. This is such a simple and elegant tool and extremely useful for whole team, testers and developers alike. This was a very brief introduction of JUnit, since idea was to make you familiar with the concept and tool. |