Maven Surefire: run one unit test

I know that you can run a specific test class with -Dtest=MyTest . But is it possible to run a specific test inside this class?

those. if MyTest defines testFoo() and testBar() , is there a way to indicate that only testFoo() should be executed?

I know this is difficult to do in the IDE, but sometimes I need to run tests on the command line on another server.

+4
source share
4 answers

It will be available as Surefire 2.8, see SUREFIRE-577

+3
source

From Performing a Single Test Using the Maven Surefire Plugin

With version 2.7.3, you can run only n tests in one test class.

NOTE: it is supported for junit 4.x and TestNG.

You should use the following syntax

mvn -Dtest=TestCircle#mytest test

You can also use templates.

mvn -Dtest=TestCircle#test* test

+5
source

Do not think that it is available. You can get around this by passing some system properties and ignore the execution of tests based on the value of the property. However, this does not seem to add much significance. There is also TestNG, which offers additional features.

http://maven.apache.org/plugins/maven-surefire-plugin/examples/testng.html

+1
source

To run one test at a time, run mvn test

 mvn -Dtest=MyUnitlTest test 

To run one test at a time and a specific method from it:

 mvn -Dtest=MyUnitTest#method test 

where MyUnitTest is the name of your test, and #method is the name of your method.

Run tests using surefire:

 mvn surefire:test 
0
source

Source: https://habr.com/ru/post/1341720/


All Articles