0

I'd like to know if there is any way to gather a set of test classes together and to run one category of tests that is common for for those tests. I'll try to explain on an example:

I have those 2 Categories:

public interface Slowtests{}
public interface Fasttests{}

And the following classes and methods:

@Category({SLowTests.class, FastTests.class})
Class A extends TstBase {

    @Category({SLowTests.class})
    void a1() {}

    @Category({FastTests.class})
    void a2() {}

    @Category({SLowTests.class, FastTests.class})
    void a3() {}
}

@Category({SLowTests.class, FastTests.class})
Class B extends TstBase {

    @Category({SLowTests.class})
    void b1() {}

    void b2() {}
}

@Category({SLowTests.class, FastTests.class})
Class C extends TstBase{
    void c1() {}
    void c2() {}
}

Now let's say I'd like to run all Fast Tests classes from A and B and C under same Test Suite and to run only the tests annotationed with FastTests category.

Hope my question is clear enough. Please advise what can I do?

npe
  • 15,395
  • 1
  • 56
  • 55
Mickey Hovel
  • 982
  • 1
  • 15
  • 31

1 Answers1

1

Define your test suite like this:

@RunWith(Categories.class)
@Categories.IncludeCategory(FastTests.class)
@Suite.SuiteClasses( /* Your test classes here */)
public class FastTestSuite {
}

Here's the official documentation and example.

npe
  • 15,395
  • 1
  • 56
  • 55
  • Thank you. Is there any chance that class A and B would inherit from lets say Class D that would extend TstBase and A and B will extend D instead of TstBase? Or to run a whole Package of TestClasses instead of writing each class in the SuiteClasses? – Mickey Hovel May 04 '15 at 06:52