Question

Please excuse the newb question - my conceptual models are still quite incomplete...

I'm trying to re-execute TestNG tests from a command line using maven and surefire. My command line looks like:

D:\workspaces\workspace01\aptest>mvn clean install surefire:test -Dtests=myTestNGSuite test

Clearly I'm not getting it because the output I end up with includes:

[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ aptest ---
[INFO] Skipping execution of surefire because it has already been run for this configuration

How do I clear out the configuration so I can re-run my TestNG suite from the command line? Is there a better way to run TestNG suites from the command line?

TIA, -->Aaron

Was it helpful?

Solution 2

The test goal of the surefire plugin is automatically run in the test phase so the first time just run

 mvn clean install -Dtest=MyTestNGTest

and then if you want to re run do a

mvn install -Dtest=MyTestNGTest

Note that I am not calling the clean goal so that only your changes of test cases or code are recompiled and that I am NOT invoking the test goal of the surefire plugin.

OTHER TIPS

Based on the command you've given

mvn clean install surefire:test -Dtests=myTestNGSuite test

BTW: Where the parameter tests should be named test

which means to run through the install life-cycle which means to run through the following steps:

  • validate
  • initialize,
  • generate-sources,
  • process-sources,
  • generate-resources,
  • process-resources,
  • compile,
  • process-classes,
  • generate-test-sources,
  • process-test-sources,
  • generate-test-resources,
  • process-test-resources,
  • test-compile,
  • process-test-classes,
  • test,
  • prepare-package,
  • package,
  • pre-integration-test,
  • integration-test,
  • post-integration-test,
  • verify,
  • install

as you can see that within this life-cycle the test phase has already been run...in Other words the surefire:test does not make sense nor the test which would run the life-cycle like this:

  • validate
  • initialize,
  • generate-sources,
  • process-sources,
  • generate-resources,
  • process-resources,
  • compile,
  • process-classes,
  • generate-test-sources,
  • process-test-sources,
  • generate-test-resources,
  • process-test-resources,
  • test-compile,
  • process-test-classes,
  • test,

So to run the suite within TestNG it is sufficient to call Maven like this:

mvn -Dtest=myTestNGSuite test

or if you have run the test life cylce before this can be shortent to:

mvn -Dtest=myTestNGSuite surefire:test

Furthermore usually you shouldn't use test suites neither in JUnit nor in TestNG cause maven-surefire-plugin will automatically recognize the unit tests within the correct locaiton (src/test/java). so there is no need to write Test Suites. BTW you should define an more up-to-date version of the maven-surefire-plugin (2.13 in the meantime).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top