Failing to call single junit test method using maven from command line - java

I am using command like mvn -q -Dtest=MyJUnitTestClassName#runSingleTest testas per maven & junit documentation it should run ONLY the runSingleTest test method. but problem is all tests are running.
I am using maven3 and junit4.
mvn -q -Dtest=MyJUnitTestClassName#runSingleTest test

Try quotes around your class and test (i.e. -Dtest="MyJUnitTestClassName#runSingleTest"). I use Maven 3.3 and JUnit 4 and the syntax you listed works for me, but that behavior sounds similar to issues with some versions of the SureFire plugins.
Run a single test method with maven

Related

Unit test fails on build from Intellij but passes from terminal

I have a big java project. Using maven to automate the build and manage dependencies and JUnit for the unit testing.
When i'm running mvn clean install from Intellij the build fails because of one unit test that fails.
The test succeeds when ran manually.
Also, executing mvn clean install from the terminal succeeds. (all tests pass)
I'm not sure where to look for the problem here.
Thanks!

Using maven to create junit xml reports of jar

I have inherited a codebase whereby we have a maven project of component tests that use junit as the framework that runs the tests.
Everything runs OK, but the problem is that these tests must be compiled into a jar-with-dependencies so that they can be run on a standalone computer with very limited outwards connectivity (e.g does not have access to maven central).
I have managed to create a runnable jar with dependencies which I can run using junit.jar and the command line like so:
java -cp jar-with-dependencies.jar:junit.jar junit.jar org.junit.runner.JUnitCore com.testsuite.AllTests
This works but the problem is that I also need to output the junit results into XML, like maven's surefire plugin does.
My question is, can I run this jar-with-dependencies using maven such that it creates the junit xml reports?
I can successfully run the tests using exec-maven-plugin which essentially runs the previously stated command

How to rerun TestNG failed tests via Maven command

Basically the header says it all, imagine I ran a testsuite, now some of the test have failed and I want to rerun those tests. I know that there is testng-failed.xml file generated by surefire plugin but I don't know how to pass that file as a parameter to TestNG through Maven. This is what I tried but unfortunately none of these commands have worked (they run all the tests again).
mvn verify -DsuiteXmlFile=testng-failed.xml
mvn verify -DsuiteXmlFile=target/surefire-reports/testng-failed.xml
Assuming you are at the root of the project and it has a standard layout, you can run:
mvn -Dsurefire.suiteXmlFiles=target/surefire-reports/testng-failed.xml test
You should try the correct parameter which is based on the documentation
mvn -Dsurefire.suiteXmlFiles=testng-failed.xml
A little bit late but for all who also stumble upon this question, khmarbaise answer works if you add the appropriate maven lifecycle.
mvn -Dsurefire.suiteXmlFiles=<path to testng-failed.xml> test

Unable to run integration test without compiling (with failsafe)

I currently try to run an integration test with maven failsafe, like described in here: reference link .
For this, I got 3 Modules: datamodule, datamodule2 and testmodule (all covered by a parent pom). testmodule depends on the two other modules. It got an test in src/test/java/ named MyTestIT.java. If I try to run the test with mvn clean test failsafe:integration-test, everything runs fine, but if I only run mvn failsafe:integration-test, it does not work. Does somebody know how it's this way?
If I try to run the test with surefire, for example with mvn test -Dtest=MyTestIT, it says it can't find MyTestIT in datamodule, and I need to set -DfailIfNoTests=false. If I try to run it with mvn test --pl testmodule, it says it can't find the dependencies (this only happens when they are not installed, but I don't want to call install everytime I run a test).
Is there any way of setting this in a pom, either in the parent pom or in the project pom? Or any other way of saying to maven "only run the integration tests, use the right dependencies and do not install everything"?

How to run Maven unit test (testng) on Eclipse?

I have a Maven project and I have included some unit tests. I can run those unit tests from command line using
mvn test -Dtest=AppTest
It will run the unit test (AppTest class) without any problems. But if I tried to run the test on Eclipse as JUnitTest, I got an error saying
"No Tests found with test runner 'JUnit 3'"
I know the test (AppTest) is not a JUnit test but I didn't see "maven" option if I right clicked on the test class.
Do you know how I could run the tests on Eclipse?
If those are testng tests, then you can download the eclipse plugin for TestNG and right click and run them as test class. Testng plugin here
If you want to run the command line way of maven, you would need the maven plugin for eclipse from here
Then you can right click your project and you should see an option of Run As -> Maven Test. You would need to set relevant arguments in the surefire plugin of pom or use run configuration to specify parameters like you did in -Dtest
I would suggest the testng plugin which would be simpler to just select the class and run the class or a single case or a package even.

Categories

Resources