Run Custom Test Task in Gradle without recompiling - java

I have a Gradle custom Test task to run my Integration Tests. I would like to be able to run this without Gradle automatically going through all previous phases and just running the test. Is there a way to do this without -x for each build step?

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!

In inteliJ with a gradle multiproject, how do I set the default test to capture data from?

My project (kotlin & java on gradle) has 3 subprojects with tests.
I can run the individual project test tasks on the subprojects fine and have inteliJ capture the test results in it's windows in the IDE.
However, if I run the top test task at the root project, while the tests are indeed executed, inteliJ doesn't receive any test events.
Is there a setting that collates test results?
and if not,
Is there a setting either in gradle or in inteliJ to set a subproject as a focus to collect events from?

Interaction between Gradle and Jenkins in smaller builds

I'm working on a Java application that is build by Gradle and will be integrated into Jenkins.
Ignoring Gradle for a moment, one would setup multiple stages in Jenkins (e.g. Build, Test, Deploy) which are then executed step by step and also shown in the GUI.
In Gradle I can use the Java plugin to get a lot of predefined tasks (like build and test). Since build depends on test I basically run a pipeline (the dependency graph) every time I execute build.
What confuses me is how Jenkins and Gradle are playing together in this case.
Due to the dependencies in Gradle my Jenkins pipeline shrinks down to (more or less) a single stage and the stages executed in Gradle are hidden in the Jenkins UI.
Is this the "normal" way of doing things? Having all the build logic in Gradle (as it is a build tool after all) and having Jenkins only for the triggers that allow me to automatically execute tasks?
In case of Gradle, it is a single command to execute the compile, build goals. It basically performs the build process and finally creates the jar/war file in the end. In case of Jenkins, you need to perform the pipeline processing using the Jenkins stages. The stages may be compile classes, test for executing unit test cases, code analysis using sonar, security check using checkmarx etc. The following snippet will give you an idea of stages in Jenkins pipeline.
stages {
stage('Compile') {
steps {
gradlew('clean', 'classes')
}
}
stage('Unit Tests') {
steps {
gradlew('test')
}
post {
always {
junit '**/build/test-results/test/TEST-*.xml'
}
}
}
....
.....
To know more details about the flow, refer below the following links.
https://bmuschko.com/blog/jenkins-build-pipeline/
https://docs.gradle.org/current/userguide/jenkins.html

Can Maven do this? Run selenium test, generate report, and then execute an jar file

Currently I have a selenium test project, I am trying to automate this process:
1. run a selenium test
2. generate a report (surefire?)
3. and do some java code execution (jar)
Is it possible to do this by configuring them in maven?
I am new to maven, not sure if maven can do the job?
Yes, maven will do that. All you need to do is this:
1. Run tests in the "test" phase of the Maven lifecycle.
2. Generate a report. If you are using Surefire with TestNG, in that case
TestNG automatically generates the report once you trigger its tests from
the "test" phase. If you need to post-process generate a report, then
you can create a "maven exec" task and bind it to the "verify" phase of
the lifecycle. One thing I do sometimes is generate HTML reports using a
XSLT transformation using the xml-maven-plugin, triggered in the verify
phase.
3. I believe the 'package' phase will generally .jar your code up into a jar.
You can change that configuration to do what you need it to though.
4. Then, finally, create a "maven exec" task to run the .jar file at the end.
I think you could bind that to the "deploy" phase of the lifecycle.
Then, to execute that entire lifecyle, it is something like this:
mvn clean compile test-compile test verify package deploy

How to run selenium test cases in jenkins?

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.

Categories

Resources