Doctor Who
Doctor Who

Reputation: 1649

Maven: Running all tests from multiple classes + one test from another class

I have a bunch of classes that have multiple tests in them. Is it possible to run all the tests from 3 classes and then just one or two tests from another class?

I thought something like this would work but I can't get it to run:

mvn -Dtest=WTest,XTest,YTest,ZTest#thisTest test

I am wanting to run all the tests in class W,X and YTest and just the test named thisTest in class ZTest.

Upvotes: 2

Views: 1665

Answers (1)

Will Keeling
Will Keeling

Reputation: 22994

I'm not sure that this is actually supported. Having spent the last half hour or so looking at the source code of JUnit4Provider it seems that surefire will run in 'whole class mode' (when you specify the name of the test class) or 'individual method mode' (when you specify the name of the method in the test class) but not both combined at the same time.

However, I did find a workaround. You should be able to do this:

mvn -Dtest=xxx.xxx.WTest#*Test,xxx.xxx.xxx.XTest#*Test,xxx.xxx.xxx.YTest#*Test,xxx.xxx.xxx.ZTest#thisTest test

So essentially you're running the tests in 'individual method mode' using the *Test wildcard to specify all the test methods in WTest, XTest, and YTest - whist only running thisTest in ZTest. That obviously assumes that the names of the methods in your test classes end with Test

Note that for this to work I had to use the fully qualified class names (which is what the xxx.xxx.xxx is supposed to show).

Upvotes: 1

Related Questions