Advantage of using Jtest over JUnit

Unit testing is one of most important and useful task to be done by developer at the stage of coding, irrespective of language in which he/she is coding. The main objective of unit testing is to take the smallest possible testable code (generally a method) and determine whether it behaves exactly as per the requirement. The main advantage of doing unit testing is to find the functional defects in the code at an early stage, which helps in increasing the productivity and efficiency.

In Java we have JUnit, a widely used open source frame work for doing unit testing .JUnit framework provides assertions (helper methods) that help in testing the functionality of the source code. JUnit automatically generates the skeleton of the test class and test methods, where the developer has include JUnit assertions related code to test the functionality. When we run the test class internally, JUnit runner class will invoke the tester methods and run the tests. The test results (passed, failed and errors if any) are generated in a report. The developer is required to edit/modify the source code corresponding to the failed test cases. The tests are re-run and once they are passed, the developer can ensure the correctness in the logic written within the application. For testing Server side applications (Jsp’s, servlets, EJB’s etc.) there is a unit testing frame work called cactus which is built on top of JUnit. Although the JUnit test cases can be reused, the developer has to spend a lot of time to write the assertions on his own .For generating unit test cases automatically we have commercial tool from Parasoft called Jtest. Apart from Unit testing, Parasoft Jtest tool also provides additional features like code coverage and static code analysis.

Jtest has the capability to analyze Java code and automatically generate the unit test cases with assertions. It generates the test cases based on the methods input and return value in your actual class. If required the developers can modify the test case methods generated and use them. It generates a separate Jtest project with same package structure as of the actual project .This helps in increasing the readability of the test classes generated.  All the test classes generated will have the same class name appended with the Jtest keyword. Jtest also provides options, on the extent to which the java code needs to be analyzed for generating the test cases. If ‘through checking’ is selected, Jtest generates  more number of test case methods by using different combinations of inputs .Existing JUnit test cases can also be reused in Jtest. Test case parameter values can be fed from an external excel file or can be internally generated within Jtest. The internally generated excel file will have different combination of values (auto generated or manually added) required for a specific test case. The code required to connect the data source with the unit test test case is auto generated by Jtest, thereby saving further time. Jtest also provides a feature for doing regression testing.
We can also get code coverage details along with the test case results upon execution. Jtest comes with cactus framework for testing server side components. Jtest can automatically create stubs for external resources like database connections. Jtest has 1200+ built in rules for doing static code analysis.

Based on the above comparison analysis, using Parasoft Jtest will not only simplify the unit testing activity but also saves effort over using JUnit.

Leave a Reply

Your email address will not be published. Required fields are marked *