Grouping Unit Tests
[wp_ad_camp_5]
At times there are certain set of unit tests we want to execute automatically. These tests may be critical or have been simply grouped for some reasons. To group JUnit test cases, we use @Suite.SuiteClasses annotation.
Environment
- Eclipse Mars.1
- JDK 7
- Ubuntu 14.04 LTS
- JUnit 4
Using @Suite.SuiteClasses
To group some tests together, we proceed by creating an empty class annotated with @Suite.SuiteClasses and indicating which test classes to include.
1 2 3 4 5 6 7 8 9 10 | package com.turreta.junit4.suite.example; import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({TestCase001.class, TestCase002.class}) public class SuiteTest { // No properties and methods here } |
That’s all!
[wp_ad_camp_4]
To run only the set of tests via Maven, use:
1 | mvn test -Dtest=SuiteTest |
As you can see TestCase003 was never executed.
Download the Codes
https://github.com/Turreta/java-junit4-suite-example
[wp_ad_camp_2]