Thursday, May 12, 2011

JUnit 4.0 - Creating a TestSuite

I recently enrolled in a study group Test Driven Development using JUnit 4.0 at diycomputerscience.com. The first activity of this week (Week 2) was create a test suiteusing @RunWith annotation.
@RunWith is an annotation provided by JUnit 4 to allow test to be executed using custom runner. For example, Spring framework provided a custom runner SpringJUnit4ClassRunner.java, to execute test in Spring Test Framework context.
To create a TestSuite, we can use the built-in runner provided by JUnit Suite.java , which expects a list of test classes to be executed.

Sample code to create TestSuite