I have to mark one test with multiple test categories using JUnit 4.11 annotation @Category. Is it possible? If yes, please, give a little example code.
org.junit.experimental.categories From a given set of test classes, runs only the classes and methods that are annotated with either the category given with the @IncludeCategory annotation, or a subtype of that category. Note that, for now, annotating suites with @Category has no effect.
You declare these objects as a private variable, and initialize them by overriding the setUp() or via the constructor. You can perform clean-up operations by overriding tearDown() . Each test method runs on its own TestCase instance with its own set of text fixtures.
@Tag is a repeatable annotation that is used to declare a tag for the annotated test class or test method. Tags are used to filter which tests are executed for a given test plan. For example, a development team may tag tests with values such as "fast" , "slow" , "ci-server" , etc.
Pass an array of categories, as shown in the javadoc.
@Category({SlowTests.class, FastTests.class})
public static class B {
@Test
public void c() {
}
}
public static class B {
@Test
@Category( { SlowTests.class, FastTests.class })
public void c() {
}
}
This is taken from the javadoc for Categories
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With