I have a test which consists of both junit test and testng tests. It works fine when i run 'mvn test' from parent pom, but testng tests fail while building in jenkins. I need a way to skip testng tests from running in jenkins.
You said you use jenkins so i assume that you are using maven plugin :
Have you tried to skip test cases in your Maven run? Use the code below in maven properties section of maven plugin:
maven.test.failure.ignore=true
Or
please use below code in properties section of maven plugin to skip the test cases
skipTests=true
Hope this helps
It's better to set it up via runtime in Jenkins' job configuration:
Invoke Top Level Maven -> Advanced.
Add maven.test.skip=true
Once the tests are OK, just remove this line.
You can disable test execution in runtime as well:
mvn -Dmaven.test.skip=true
Related
i am trying to build maven command to run specific test:
i want to be able to execute this:
mvn test
mvn integration
mvn specificdata
so each test will go into a folder and run the suite
src/test
src/integration
src/specificdata
mvn test works with the test folder but when i run
mvn specificdata i get
[ERROR] Unknown life-cycle phase "specificdata".
same for integration
how can i make mvn run these tests independently?
This cannot be done in the way you describe it.
test is a phase and as such, part of the standard lifecycle. Calling mvn test does not only run tests, but executes the phases before test as well.
The standard lifecycle also offers phases for integration tests, esp. integration-test. Integration tests are usually put into src/test as well and distinguished by a naming convention. But beware: Calling mvn integration-test will call all previous phases (including test, compileetc.) as well.
https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
Following command doesn't run any of my tests :
mvn spring-boot:run
whereas plain old mvn test does.
I have added these annotations to the tests :
#RunWith(SpringRunner.class)
#SpringBootTest
I do not see any relevant information on the plugin documentation pages, either here or here
Spring boot maven plugin
Requires a Maven project to be executed. Requires dependency
resolution of artifacts in scope: test. Since version: 1.1. Binds by
default to the lifecycle phase: validate. Invokes the execution of the
lifecycle phase test-compile prior to executing itself.
More details
Maven lifecycles:
validate compile test ...
More details
To sum up: spring-boot:run only compiles tests and execute maven validate phase. One of the possible solutions to execute tests before start of the application: mvn test spring-boot:run
I use junit in my java project (developed using intellij idea) for unit test, and I want to configure build step in team city to run my unit tests only. I also use maven to build my project. It works when I set goals for maven to "clean compile" but I dont know how to configure build step to run unit tests.
Also in command line. when i run "maven test" it runs unit tests correctly and shows the failures.
I can't comment on TeamCity, but I'll try to help anyway out of my maven knowledge.
So first of all mvn clean compile will never run your unit tests, because maven has a concept of lifecycle and testing phase is coming after compile phase.
When you run mvn test it will run all the face up to (including) the test phase so the unit tests will run as a part of maven default lifecycle.
Now you're asking about a "build step for running unit tests" from which I conclude that you need a separate step. In maven phase is nothing more than running a series of plugins. In maven plugin has goals, so you can run a plugin responsible for running unit tests directly.
In maven this plugin is called "surefire" and a goal is called "test", so you can run:
mvn surefire:test
Given the classes (production code and tests) are compiled, you will see that this only runs your unit tests. So this probably has to be configured in Team City.
I have some Unit tests, that when I try to run, it automatically creates Maven run/debug configuration, instead of JUnit (the integrated IDEA tab).
For some tests it does use JUnit run\debug configuration and manually - I can create both Maven and JUnit.
How do I make JUnit to be the default test runner ?
The problems is that I had maven runner plugin installed, causing all my tests to run with Maven
You can use the maven option "-Dskip=true" to suppress the maven test execution, and you can add your own test configuration to the build process. This screenshot was taken form IntelliJ 15.0.2.
Update: maven option
There is a open source project called Apache Any23 , the instructions to checkout and build it are listed at the link below.
https://any23.apache.org/build-src.html
I am unable to to do a mvn clean install by following the instructions because the integration test phase gets invoked by the maven invoker plugin , I have user -Dskipstests etc , but the invoker plugin still gets invoked , I need you to bypass/suppress the integration test phase and the surefire plugin tests and do a successful build.
It this requires a pom.xml change, I need you to send me the updated file and let me know what changes were made.
Thanks
Does the project use the Failsafe plugin to run the integration tests? If so, try to skip them this way:
mvn install -DskipTests
However, since skipTests is also supported by the Surefire Plugin, this will have the effect of not running any tests. If, instead, you want to skip only the integration tests being run by the Failsafe Plugin, you would use the skipITs property instead:
mvn install -DskipITs
If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler plugins.
mvn install -Dmaven.test.skip=true
Read more about this here.