Reputation: 8922
When running the JUnit tests from Eclipse, where should I specify the @category
variable?
For example, when using Maven via command line, I can specify the JUnit to run the tests cases annotated by "com.abc.MyTests" like this.
mvn test -Dgroups="com.abc.MyTests"
It looks like in the Run Configurations, I can define environment variables in the Environment tab or specify arguments in the Arguments tab. However neither worked... (Maybe I didn't configure correctly)
Upvotes: 3
Views: 1196
Reputation: 8658
If you run JUnit tests from Eclipse, you normally don't do this via maven, so providing -Dgroups
-like command line options specific to maven will not work.
You could create a maven configuration in Eclipse and invoke that from Eclipse, but I assume that is not what you want.
I suffered from this problem myself, and ended up creating dedicated suite classes:
@RunWith(Categories.class)
@Categories.IncludeCategory(com.abc.MyTests.class)
@SuiteClasses( { AllTests.class } )
public class MyTestSuite { }
This assumes there is another class AllTests
summarizing the total set of test classes:
@RunWith(Suite.class)
@SuiteClasses({
Test1.class,
Test2.class,
...
})
public class AllTests { }
You can then run MyTestSuite
directly from Eclipse.
Not exactly ideal, since it requires maintaining the AllTests
class, and an extra class for any category you want to test from Eclipse.
Upvotes: 3