Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Surefire: run a single unit test

I know that it's possible to run a specific test class with -Dtest=MyTest. But is it possible to run a specific test within that class?

I.e. if MyTest defines testFoo() and testBar(), is there a way to specify that only testfoo() should be run?

I'm aware that it's trivially easy to do this in an IDE, but I occasionally need to run tests on the command line on another server.

like image 836
George Armhold Avatar asked Jan 20 '23 08:01

George Armhold


1 Answers

From Running a Single Test Using Maven Surefire Plugin

With version 2.7.3, you can run only n tests in a single Test Class.

NOTE : it's supported for junit 4.x and TestNG.

You must use the following syntax

mvn -Dtest=TestCircle#mytest test

You can use patterns too

mvn -Dtest=TestCircle#test* test

like image 60
gunalmel Avatar answered Jan 28 '23 07:01

gunalmel