Jenkins Pipeline not execute my UnitTests.exe - unit-testing

I am doing a jenkins pipeline with different stages.
I stuck now at executing my unit-tests after build
This is my pipeline (it is shorted)
stage('Build') {
steps {
dir('UnitTests') {
bat 'make TEST_FOLDER=UnitTestFiles all'
}
}
}
stage('Run Unit-Tests') {
steps {
dir('UnitTests') {
bat 'UnitTests.exe --gtest_output=xml:UnitTestReport.xml'
}
}
}
-> Build is done successfully, I can see UnitTests.exe in the workspace, but
-> Jenkins is not running UnitTests.exe.
Why?

Related

Nullpointer Exception on Jenkins

I am getting an error on my Jenkins build, which I checked in the logs is using the command
[![enter image description here][1]][1]
It shows Tests run: 211, Failures: 1
But when I run the same maven command under my project, all tests pass, and it shows
Tests run: 211 Failures: 0
that's weird, and I have no idea what could be going on and how to reproduce the issue
. The same branch that I am working on locally is deployed through Jenkins.
On the jenkins the test function that is failing is this:
public void test_tbe_event_cancel() throws I0Exception {
System.out.println("Inside test_tbe_event_cancel");
givenTheTbeCancelFixMessage(testTBECancelFix()).processTBEHistoricCancel(historicMessageEventHandler, positionEvent -> {
(positionEvent.getSideMarkPosition(), 7500.0);
(positionEvent.getCurrentPosition(), 7500.0);
(positionEvent.getBuyQuantity(), 7500.0);
1)
.andAssertBookPosition(bookPosition -> {
(bookPosition.getSideMarkPosition(), 7500.0);
(bookPosition.getCurrentPosition(), 7500.0);
(bookPosition.getBuyQuantity(), 7500.0);
(bookPosition.getSellQuantity(), 0.0);
(bookPosition.getSellValue(), 0.0);
1);
System.out.println("exiting test_tbe_event_cancel");
}
and the exception is :
NullPointerExceptionm which is happening on the above function: test_tbe_event_cancel
at line .andAssertBookPosition(bookPosition -> {
Any ideas on how do I debug this issue, or reproduce it on my local system.
I initially tried with mvn clean install command which worked and then tried the
longer maven command used on Jenkins box that too works on local box surprisingly, I was
expecting that the error could be reproduced if I use the exact same command, but it
didn't happen
[1]: https://i.stack.imgur.com/nF02b.png

Sonarqube task in Gradle does not produce test coverage

I have multi-project Gradle script. I added to the root project:
buildscript {
repositories{
...
}
dependencies { classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1") }
}
apply plugin: org.sonarqube.gradle.SonarQubePlugin
sonarqube {
properties {
property "sonar.junit.reportsPath", "$projectDir/build/test-results/test"
property "sonar.host.url", "http://localhost:9000"
property "sonar.verbose", "true"
}
}
Sonarqube shows the correct number of tests, but coverage is 0.
I use Gradle 3.0, Java 1.8.0_45, Sonarqube 6.1.
Gradle console shows many "Class not found" messages.
Gradle console also shows message:
"Reports path contains no files matching TEST-.*.xml :
myPath\build\test-results\test"
, which is correct, since that particular project does not have any tests.
In my child project, I have:
apply plugin: 'java'
apply plugin: "jacoco"
jacocoTestReport {
reports {
xml.enabled = true
}
}
check.dependsOn jacocoTestReport
Run Gradle task "sonarqube" of the root project.
No SonarQube Analyzer or plugin executes your tests or the coverage calculation for you. You must do those things before analysis and feed the resulting report(s) into your analysis.

Running test task on gradle root project does not run test task on subprojects

In my multiproject I am running test task on root project and expecting that it will run test task on subprojects and produce a single test report. What I observe is that it never runs test task on subprojects. Is my expectation incorrect" DO I need to do any special configuration in my gradle scripts?
Note that I have no tests in my root project.
I think, this snippet from Gradle User Guide should help you out:
subprojects {
apply plugin: 'java'
// Disable the test report for the individual test task
test {
reports.html.enabled = false
}
}
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
reportOn subprojects*.test
}

How to run integration tests from IntelliJ context menu for gradle project?

Using IntelliJ IDEA 14.0.2, I have imported a gradle java project. We have set up a sourceSet and configuration to separate integration tests from unit tests. (our integration tests are in the test source tree, but in their own package). Relevant bits from the build.gradle are:
sourceSets {
test {
java {
exclude '**/it/**'
}
}
integTest {
java {
srcDir 'src/test/java'
include '**/it/**'
}
resources {
srcDir 'src/test/resources'
}
compileClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
runtimeClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
}
}
configurations {
integTestCompile.extendsFrom testCompile
integTestRuntime.extendsFrom testRuntime
}
idea {
module {
scopes.TEST.plus += [ configurations.integTestCompile ]
}
}
task integTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
}
This works fine from the command line. But when I open up the source of an integration test in IntelliJ and right-click to run it, IntelliJ launches the "test" task rather than the "integTest" task. How do I get IntelliJ to launch the correct task?
Alternatively, how can I make the test task delegate to another task based on the contents of the "--tests " arg?
Follow this: gradle settings > Gradle > Runner and check Delegate IDE build/run actions to gradle. Then apply and Ok.
Good luck!
Right-click on the test on file and you should see a menu option for Create Run Configuration >. Select that an in the dialog, modify the Tasks option. Change that to integTest and click OK. From that point, you might have to run the test using the menu system rather than the context system. i.e. Run > Run...
My solution is to configure IntelliJ to not use Gradle as a test runner, but to execute the tests with the built-in JUnit runner. This is just a configuration option in IntelliJ IDEA at the Gradle settings.
See https://www.jetbrains.com/help/idea/gradle-settings.html#gradle_tests for details.

How to specify Gradle wrapper with Jenkins JobDSL?

The JobDSL spec currently has:
job {
steps {
gradle('build')
}
}
but that creates a job that errors with:
FATAL: Unable to find Gradle Wrapper
How does one specify the Gradle wrapper to use? I don't see it documented in https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-reference#gradle.
It's not a standard thing to do, you have to escape out to a configure block:
job {
steps {
gradle('clean build', '--info --refresh-dependencies', true) {
it / wrapperScript('$NEBULA_HOME/gradlew')
}
}
}