Chapter 4. Managing test suites
This chapter covers
- Manually collecting tests into custom test suites
- Automatically collecting tests into different kinds of test suites
- Ordering and filtering tests in test suites
- Using Parameterized Test Cases to build a data-driven test suite
In JUnit, the smallest unit of “test execution” is the test suite. JUnit doesn’t actually execute individual tests, but only executes test suites, so in order to execute your tests, you need to collect them into a test suite. The recipes in this chapter describe different ways to create and manage test suites.
The simplest test suite to create consists of all the tests in a test case class. This is so simple that JUnit does it for you. See recipe 4.1, “Let JUnit build your test suite.” If you need to create your test suites by hand, go to recipe 4.2, “Collect a specific set of tests.” If you have data-driven tests and don’t want to write by hand a bunch of test methods that simply use your test data, see recipe 4.8, “Build a data-driven test suite.” After that you’ll probably want to move your test data outside the code. For that, see recipe 4.9, “Define a test suite in XML.”