Grouping Silk4J Tests

You can use the SilkTestCategories class to run Silk4J tests, write TrueLogs, and filter or group tests with annotations. Define categories of test classes to group the Silk4J tests into these categories, and to run only the tests that are included in a specified category or a subtype of that category. For additional information, see Grouping tests using JUnit categories.

To include a Silk4J test in a category, use the @IncludeCategory annotation.

Using the category SilkTestCategories class enables you to write TrueLogs for the Silk4J tests included in the category. You can also use the SilkTestSuite class to write TrueLogs. For additional information, see Replaying a Test Method from the Command Line.

Example

The following example shows how you can execute the Silk4J tests that are included in a category.

To import the Category class you will need to add a line similar to the following to the start of your test script:
import org.junit.experimental.categories.Category;
Categories can be implemented as classes or as interfaces, for example:
public interface FastTests {}
  public interface SlowTests {}
You can flag an entire class with a category. In the following code sample, all methods in the class are flagged with the category SlowTests:
@Category( { SlowTests.class})
public class A {
  @Test
  public void a() {
    ...
  }

  @Test
  public void b() {
    ...
  }
}
  
You can also flag individual methods in a class with a category. In the following code sample, only the method d is flagged with the category FastTests:
public class B {
  @Test
  public void c() {
    ...
  }

  @Category(FastTests.class)
  @Test
  public void d() {
    ...
  }
}
You can flag a class or method with multiple categories:
@Category( { SlowTests.class, FastTests.class })
public static class C {
  @Test
  public void e() {
    ...
  }
}
To run tests in a particular category, you need to set up a test suite:
@RunWith(SilkTestCategories.class)
@IncludeCategory(SlowTests.class)
@SuiteClasses( { A.class, C.class })
// Note: SilkTestCategories is a kind of Suite
public static class SlowTestSuite {}