Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

JUnit + Jtest = Automated Test Case Design and Static Analysis : Page 2

Jtest, an automated unit testing and static analysis tool, extends JUnit to provide automatic test case generation and static analysis functionality.


advertisement
How to Extend JUnit with Jtest: A Simple Example
To better understand how Jtest can extend JUnit, review a simple example of these two tools working together. Assume you have just written Simple.class, a very basic class (see Listing 1 for its source code), and you want to verify whether it is correct and robust before you start working on another class.

If you relied only on JUnit, you might start the testing process by creating a test class like the one shown in Listing 2.

If you compile this test class then execute it using JUnit, all the test cases will pass. You probably would then check the source code into the source code repository and begin working on the next class.



However, if you use both Jtest and JUnit in this scenario, you would perform the following steps:

  1. Load Simple.class into the Jtest Class Testing UI.
  2. Click the Start tool bar button to start the test (as shown in Figure 1).

Testing Simple.class in Jtest
Figure 1: Testing Simple.class in Jtest

Jtest examines the class under test, statically analyzes the class's source code, designs test cases that test the class's construction and attempt to cover every branch of every method, and then executes both the automatically generated test cases and the six JUnit test cases represented in the SimpleTest test class. This entire process takes less than 25 seconds. If the class contained Design by Contract comments, Jtest would have also designed test cases that verify the class's functionality.

When the test is completed, Jtest reports the results shown in Figure 2.

The Results of the Simple.class Test
Figure 2: The Results of the Simple.class Test

By using Jtest with JUnit, you identified 12 violations of Java coding guidelines and one uncaught runtime exception. In addition, you gained 15 new test cases that you can export as a JUnit test class and/or use for functionality testing.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date