简体   繁体   中英

Maven Unit Tests

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM