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
Related
I'm writing code in Intellij and have a JUnit test class included in a project and i understand that running of JUnit should always be done at build time.
Is there a way to first run the JUnit and only if there were no test error run the project itself ? I want them to run together with 1 click (NOT run them seperately/manually).
Also, i would like the above to work even when the project is packed as a .jar file.
How can it be done ?
Thanks !
In Intellij:
Run -> Edit Configurations
Create a JUnit configuration for your tests
Create a Run configuration for your project.
And on "Before Launch": Add -> Run Another Configuration and choose the one created at point 1.
It doesn't matter how your project is packed (jar, ...)
Normally this is done by using a build management tool like: maven, gradle, ant. In this way the build tool will run tests for you and stop if they fail.
With maven, it's just a command: mvn clean package exec:java which will compile code, build project, run tests and execute your code.
See example project: https://github.com/HaveACupOfJava/maven-jar-demo
Is it possible to execute a lifecycle target (e.g. integration-test) on an artefact that has been installed within the local repo?
My use case is as follows. I have a multi module project with many modules that dedicated various types of integration testing (compliance test, performance tests, etc). I need to invoke these integration multiple times with different environment configurations. These configurations are expressed as maven profiles and parameterised using properties. I want to avoid recompiling the project over and over again.
I would like to have one build CI job performing the mvn install, then separate CI jobs performing the integration tests, triggered once the build CI job has passed. The integration tests would simply invoke integration-test lifecycle phase of the installed artefact setting the profile and passing the parameters
I have tried pointing mvn at the .pom file within the local repo but this does not work. It fails because it cannot find classes within the artefact's own JAR file (as if it were not being put on the classpath) - a problem that doesn't occur if I have my integration job checkout the tree and invoke the pom.xml within the source tree.
mvn -f ~/.m2/repo/x/y/z/myproj-perftests-x.x.x-SNAPSHOT.pom integration-test -Pmyprofile -Dparam1=blah
No, it is not possible. Maven plugins (normally) only work with project sources.
If your only concern is recompiling project again and again, consider splitting your project into the core part and the integration tests part. Then when running integration tests you'll only need to recompile the integration tests part.
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 am successfully running Cucumber test on my java/maven eclipse project. But when I add my project do Jenkins I always get the following error "cucumber.runtime.CucumberException: No features found at []".
I read in this thread Setting cucumber-jvm options in Maven from the command line that:
...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)
But I am not quite sure how to do this. Can anyone help me?
PS: I am using "cucumber-java" and "cucumber-junit" dependencies.
If you're using surefire, the plugin documentation page http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html shows few options you can try to set system properties
For example you can try the systemPropertyVariables plugin settings
do you see the feature files in your target folder on your Jenkins slave ? maybe your *.feature files get excluded because of an incorrect config of your resources exclusion/inclusion in Maven ?
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).