I am trying to set the "name" option for Cucumber to be able to run a specific feature or scenario.
I have entered this,
mvn test -DCucumber.Options--name="MyFeatureName"
but it just runs all the features and doesn't give an error.
Any ideas?
Here is a snippet from the Cucumber-JVM repo on how to run the java-helloworld example by passing cucumber options:
mvn test -Dcucumber.options="--format json-pretty --glue classpath:cucumber/examples/java/helloworld src/test/resources"
Keep in mind that it will override all the options in the #Cucumber.Options annotation you have on "RunCukesTest". I haven't got it to work for my own tests but maybe this will help.
So it looks like you need to give all the options needed to run cucumber, including the java class path and where the code is located using the "--glue" parameter.
Your tests are running in separate JVM, so you need to specify that system property in the test plugin configuration (i.e. surefire or failsafe plugin config in your pom.xml).
Related
In my project (springboot, maven), I have tests annotated with #TestPropertySource({"classpath:flyway.properties", "/queries/test.properties"}) to override some properties related to my datasource.
I run the test with mvn clean test command.
Now I would like to add a new stage to my Jenkins pipeline to perform my tests on two different data sources.
Is there a way to overwrite the values in my file (test.properties) when I run the maven command? Or could I use two different files with spring profiles or something like :
#TestPropertySource({"classpath:flyway.properties", "/queries/test-${env/profile}.properties"})
Any insight would be gratefully appreciated. Cheers!
You could have different profiles and activate the right one on demand by running:
mvn -DargLine="-Dspring.profiles.active=myProfile" clean test
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
Is there a way to tell only Eclipse to skip various individual junit tests (but still run the rest of them)? I am familiar with the #Ignore annotation, but that is not what I am looking for because that will cause the tests to always be skipped.
I would like the tests to be skipped when ran by eclipse (Run As -> Junit Test) but ran in any other context, most likely during a maven build.
Any ideas?
So far the following solution has worked well. It is not a complete solution because it causes the tests to only be ran by maven when maven is invoked from the command line. For now though, it works.
When maven is invoked, the maven command line arguments are placed in the environment map (System.getenv()). When the tests are run through jUnit in eclipse, there is no entry in System.getenv() for the maven command line arguments. So, I am using jUnits Assume class to check that this property is not null for the tests that I want eclipse to skip.
Code:
Assume.assumeNotNull(System.getenv("MAVEN_CMD_LINE_ARGS"));
FYI, one downside of this solution is that eclipse marks the tests as passed instead of skipped.
I had been introduced to concept of CI lately and was trying to work on jenkins CI. I was stuck up in one thing . How to trigger executable testng files in jenkins CI. For ex locally in our machines we just run testng.xml to execute couple of test cases. In the same way how can we trigger this xml file to run in jenkins CI ?
In most cases with jenkins you wouldn't use an executable. Normally you'd run the wrapper for the tests (Junit/Nunit etc.) which Jenkins is fully capable of running on it's own.
You can use this article to run TestNG tests using Maven:
Running TestNG tests using maven
After configuration is completed just add Invoke top-level Maven targets step to the Build Steps in Jenkins (Maven plugin should be installed). The target should be test in this case.
If you will face with any errors during configuration, try to google them.
If you are not using any build tool like maven or ant, you can invoke it from command line as we'll and specify your suite file. Make sure to set the correct class paths http://testng.org/doc/documentation-main.html#running-testng
You can put this as a build step in Jenkins.
Add a compilation step prior to this step. I haven't ever tried it - have always used ant or maven, but that is where I would start exploring.
I've several Selenium tests and want to know their coverage (measured with Cobertura). I'm using Maven 2 as a build framework.
Before executing my Selenium tests, I launch the web application using mvn jetty:run.
In order for the coverage data to appear in my report, I need Jetty to use instrumented code.
I can explicitly instrument the code using mvn cobertura:instrument. But how can I tell Jetty to use the instrumented code (directory target/generated-classes/cobertura) ?
Thanks in advance
Dmitri
In the configuration element of the jetty-maven-plugin plugin entry, you can specify the element, which will cause it to use a different path to find the classes.
If you set you add the following to your jetty plugin element, I think you'll be in business:
<classesDirectory>${basedir}/target/generated-classes/cobertura</classesDirectory>