I'm trying to figure out a Maven command to execute a single JUnit @Test method
However, I have the added complication that my JUnit tests are inside a test suite being called from a wrapper class (the wrapper sets up/tears down some test data, used by all the test classes)
Wrapper class:
@RunWith(Suite.class)
@SuiteClasses({
TestClassA.class,
TestClassB.class,
})
public class TestWrapper
{
@BeforeClass
public static void dataSetup() throws Exception
{
//Create test data
}
@AfterClass
public static void dataTeardown() throws Exception
{
//Remove test data
}
}
Example test class:
@RunWith(Suite.class)
public class TestClassA
{
@Test
public void someTest()
{
//test contents
}
@Test
public void anotherTest()
{
//test contents
}
}
To execute all tests using the wrapper, I'm using the Maven command:
mvn verify -Dtest=**/TestWrapper test
I'm trying to figure out how to execute a specific test in one of the test suites, ex, only execute TestClassA.someTest
Currently, I'm just commenting out the test suites/test methods I want to skip, but there has to be a better way
This is very similar to the question here: Using Maven, how do I run specific tests?
As suggested in the linked question, I've tried using -Dtest=**/TestWrapper#someTest
, but that fails because someTest
isn't a method of TestWrapper
I've also tried -Dtest="**/TestWrapper, **/TestClassA#someTest"
That gets me a little closer, in that it does exactly what I want (runs TestWrapper
and only executes TestClassA.someTest
), but then it runs a second execution of TestClassA.someTest
alone (which fails horribly because the wrapper test data doesn't exist)