2

I am working on a project written using Maven.

If I do

mvn clean install 

then I expect that it will run the all unit tests under /test forder.

I redirected the build process and stored into an output file and tried to find out unit tests by the name. However, I wasn't able to find some of the unit tests. It seems like some of the unit tests were actually not executed during the build process.

My question is how do I know the selection of unit tests that will be executed during the build process.

2
  • 3
    Maybe you know this already and it has nothing to do with your problem, but by default, mvn only runs unit tests of classes whose names begin or end with the word "Test" like TestBogosort or PrimeFinderTest (in any package in the src/test/java folder) Commented Mar 26, 2013 at 22:30
  • Also you could just have every test print its name to stderr before running. It's crude but it will tell you. Commented Mar 26, 2013 at 22:33

2 Answers 2

2

You may try explicitly naming the group(s) in the command line like this:

mvn clean install -Dtest.groups="unit,integration" 

or simply

mvn test -Dtest.groups="unit,integration" 

This is an example of what I use daily. My tests are either in the unit or the integration group. If you wish to run all (or some) tests without the need for explicitly specifying which gorups to use you have to modify your maven configuration though.

Sign up to request clarification or add additional context in comments.

2 Comments

This is the wrong way to run integration tests cause they should be run during the integration-test life-cycle phase which is after packaging phase furthermore it is handled by the maven-failsafe-plugin instead of maven-surefire-plugin.
We've been using this approach for quite a while and I did not have any negative experience with it.
2

The unit tests in Maven will be selected by their name which should follow the naming convention

<includes> <include>**/*Test*.java</include> <include>**/*Test.java</include> <include>**/*TestCase.java</include> </includes> 

Furthermore you need to put the tests to the default location src/test/java/.

You can control running only a single test by using:

mvn -Dtest=MyTest test 

Running integration test is the job of the maven-failsafe-plugin which is handled in the integration-test phase. The naming convention for integration tests is:

<includes> <include>**/*IT*.java</include> <include>**/*IT.java</include> <include>**/*ITCase.java</include> </includes> 

To get integration tests running you need to add a configuration part for the maven-failsafe-plugin.

1 Comment

Than you, I had my tests names xxxTests, once I changed to xxxTest they were picked up.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.