I have two logical categories of tests: plain functional unit tests (pass/fail) and benchmark performance tests that are just for metrics/diagnostics.
Currently, I have all test methods in a single class, call it MyTests
:
public class MyTests
{
@Test
public void testUnit1()
{
...
assertTrue(someBool);
}
@Test
public void testUnit2()
{
...
assertFalse(someBool);
}
@Test
@Category(PerformanceTest.class)
public void bmrkPerfTest1()
{
...
}
@Test
@Category(PerformanceTest.class)
public void bmrkPerfTest2()
{
...
}
}
Then I have a UnitTestSuite
defined as
@RunWith(Categories.class)
@Categories.ExcludeCategory(PerformanceTest.class)
@SuiteClasses({ MyTests.class })
public class UnitTestSuite {}
and a PerformanceTestSuite
@RunWith(Categories.class)
@Categories.IncludeCategory(PerformanceTest.class)
@SuiteClasses({ MyTests.class })
public class PerformanceTestSuite {}
so that I can run the unit tests in Ant
separately from performance tests (I don't think including Ant code is necessary).
This means I have a total of FOUR classes (MyTests, PerformanceTest, PerformanceTestSuite, and UnitTestSuite). I realize I could have just put all the unit tests in one class and benchmark tests in another class and be done with it, without the additional complexity with categories and extra annotations. I call tests by class name in Ant, i.e. don't run all tests in a package.
Does it make sense and what are the reasons to keep it organized by category with the annotation or would it be better if I just refactored it in two simple test classes?