What Jtest Caught
To get an idea of the types of problems that Jtest identifies automatically, let's examine the uncaught runtime exception and one of the static analysis violations that Jtest uncovered. The uncaught runtime exception message shown in Figure 3
reveals that the
method is implemented incorrectly. The method should return
for the argument
, but it throws a runtime exception instead. If the error is not fixed, any application using this class will eventually crash or give incorrect results. By identifying and fixing this problem immediately, you can prevent significant grief later.
|Figure 3: A Runtime Exception that Jtest Exposed|
The violation of the PB.TLS static analysis rule shown in Figure 4 reveals that the developer of this class inadvertently wrote
case10 instead of
case 10. If the class is not fixed, it will give incorrect results when it is passed the value
10. If this problem is allowed to remain in the code, it will likely cause strange, difficult-to-diagnose errors during application testing or in the field. Once again, by identifying and fixing this problem immediately, you can prevent grief later.
|Figure 4: A Coding Standard Violation that Jtest Identified|
Create a JUnit-compatible Test Class for Automatically Generated Test Cases
Finally, assume that you want to create a JUnit test class that represents the 15 automatically generated test cases. You choose Jtest's Export to a JUnit Test Class option. Jtest instantly generates a test class that allows you to run these 15 test cases in either Jtest or JUnit. You can add more functional test cases by modifying the test methods in the automatically generated test class, and then you can run the modified test class in either Jtest or JUnit. Adding test cases in this manner enables you to verify whether the class is correct. This strategy significantly reduces the amount of code that you need to write for each testwithout sacrificing test quality.
Integrate Unit Testing into Daily Development
These days, almost every Java developer recognizes the value of practices such as unit testing and coding standard enforcement, and intends to perform them as part of his or her regular testing practices. However, these practices can be time-consuming, and most developers rarely have the opportunity to perform them as early, frequently, or thoroughly as they would like. Extending JUnit with Jtest can solve this problem. When you use both Jtest and JUnit, you can realistically integrate unit testing and coding standard enforcement into your daily development practices.