1

Possible Duplicate:
How to run junit tests by category in maven

I have a question regarding grouping tests in JUnit.

I have got a test class annotated with

@Category(IntegrationTests.class)
public class TestClass { ... }

And IntegrationTests is just an interface.

Is there anyway I can specify in maven command line that only run this category of test?

Many thanks.

Community
  • 1
  • 1
Kevin
  • 5,972
  • 17
  • 63
  • 87
  • 1
    Duplicate question : http://maven.apache.org/plugins/maven-surefire-plugin/examples/single-test.html Look at this link for all possible test cases – Phani Apr 20 '12 at 13:14

2 Answers2

4

The difference between unit tests and integration test is simple the naming convention:

**/Test*.java
**/*Test.java
**/*TestCase.java

will be recognized as unit tests. And the integration test based on maven-failsafe-plugin will be recognized by a different naming convention:

**/IT*.java
**/*IT.java
**/*ITCase.java
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Note this is the default, and can be overriden by custom rules or annotation Categories in Junit > 4.8 – Eddie Apr 25 '12 at 14:46
2

Why not rely on existing conventions?

mvn clean test will run unit tests via surefire. mvn clean verify will run integration tests via failsafe

You can use naming conventions or annotations to enforce selection.

thisIsAUnitTest.java will be executed by surefire (mvn test)
thisClassIsAnIT.java will be executed by failsafe (mvn verify)

HOW ?!

SureFire for Unit Tests

By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:

"**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test".
"**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase".

Failsafe for integratino tests

By default, the Failsafe Plugin will automatically include all test classes with the following wildcard patterns:

"**/IT*.java" - includes all of its subdirectories and all java filenames that start with "IT".
"**/*IT.java" - includes all of its subdirectories and all java filenames that end with "IT".
"**/*ITCase.java" - includes all of its subdirectories and all java filenames that end with "ITCase".
Eddie
  • 9,696
  • 4
  • 45
  • 58
  • Thanks. I don't know this. How can I specify which tests are integration test so that they are not run when I run "maven clean install"? – Kevin Apr 20 '12 at 13:17
  • Either categories http://maven.apache.org/plugins/maven-failsafe-plugin/examples/junit.html#Using_JUnit_Categories Or naming convention. I have added a bunch of details and examples above. – Eddie Apr 25 '12 at 14:45