This article is participating in the Java Theme Month – Java Debug Notes Event, see the event link for details

Running a single test method using Maven?

I know you can run all tests in a class using the following command:

mvn test -Dtest=classname

But I want to run a separate method, and -dtest = classname. methodName doesn’t seem to work.

Answer:


A lot of knowledge points, really need to write out will master ! ! !   \color{purple} a lot of knowledge points, really need to write out just can master!! {~}

To run a single test method in Maven, you need to provide the following command:

mvn test -Dtest=TestCircle#xyz test
Copy the code

TestCircle tests where the class name is xyz, and where the test method is.

Wildcards also work; It is the same in method names and class names.

If you want to test in a multi-module project, specify the module -pl where the test will be.

For integration tests, use it.test=… Option not test=… :

mvn -pl <module-name> -Dit.test=TestCircle#xyz integration-test
Copy the code

Answer:

Surefire 2.12 has issues. This is what happened when I changed the Maven-Surefire-plugin from 2.12 to 2.11:

MVN test-dtest =DesignRulesTest result: [error] unable to execute target org.apache.maven.plugins: maven-surefire-plugin: 2.12: test on project PMD: No tests performed! MVN test-dtest =DesignRulesTest: [INFO] -- Maven-surefire-plugin: 2.11: test @pmd --... Run the.net. Sourceforge. PMD. Lang. Java. Rule. Design. The DesignRulesTest test run: 5, failure: 0, error: 0, skip: 4, after a time: 4.009 secondsCopy the code

The article translated from kgs4h5t57thfb6iyuz6dqtun5y ac4c6men2g7xr2a – stackoverflow – com. Translate. Goog/questions / 1…

MVN test -Dtest=TestCircle#xyz test


Welcome to my column S t a c k O v e r F l o w . I select the best questions and answers and test them frequently in interviews ! ! !   \color{red} Welcome to my column StackOverFlow, I will filter the quality of the interview test!! {~}


There are the latest and elegant ways to do this, and I will write my thoughts on this q&A at the end of the article \color{red} has the latest, elegant implementation, and I will also write my opinion on this question at the end of the article {~}

Thank you for reading this, if this article is well written and if you feel there is something to it

Ask for a thumbs up 👍 ask for attention ❤️ ask for share 👥 for 8 abs I really very useful!!

If there are any mistakes in this blog, please comment, thank you very much! ❤ ️ ❤ ️ ❤ ️ ❤ ️