maven-surefire-plugin strange behaviour - maven

I've got a problem with maven-surefire-plugin reports. Maven version is 3.3.9, maven-surefire-plugin 2.18.1, version of JUnit is 4.12.
Tests run in Jenkins, there should be info after each test, but sometimes something goes wrong and there is no info in Console and there are no surefire reports.
Should be something like that
11:07:42 Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 194.569 sec - in com.example.content.SomeTest
11:07:42
11:07:42 Results :
11:07:42
11:07:42 Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
11:07:42
11:07:42 [INFO] -------------------------------------------------------------------
11:07:42 [INFO] BUILD SUCCESS
11:07:42 [INFO] -------------------------------------------------------------------
11:07:42 [INFO] Total time: 03:17 min
11:07:42 [INFO] Finished at: 2017-11-15T11:07:39
11:07:42 [INFO] Final Memory: 15M/377M
11:07:42 [INFO] -------------------------------------------------------------------
But as I said sometimes there are no these lines. Previous and next test classes work fine and have all info and reports as it supposed to be
Is this problem really caused by surefire-plugin or maybe it's something different?

Related

How to get code coverage on code for which the tests are in another module?

I have a maven module containing code but no tests. Tests are in another module.
code-module
test-module
I use JaCoCo to report about the code coverage, but it seems that no JaCoCo report is generated in the code-module because there are no tests to run. Without such report, the aggregate report in the test-module does not include the code coverage from the code-module's code.
How do I make sure the jacoco report is generated even when there are no tests?
Where I think the problem lies
I found out that the problem may lie with the way the maven-surefire-plugin handles the case where no tests are found.
The maven logs then show:
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) # code-module ---
followed by
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) # data-product-model ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Adding a single test class (that may be empty) changes this output to
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) # code-module ---
[INFO] Using auto detected provider org.apache.maven.surefire.junit.JUnit3Provider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.code.CodeCoverageTest
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 s - in com.example.code.CodeCoverageTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
and suddenly it generates surefire-reports/ and the jacoco.exec and site/jacoco/
(even though there are no actual tests, just an empty CodeCoverageTest.java),
so I see that the jacoco-maven-plugin is able to report:
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) # code-module ---
[INFO] Loading execution data file /workspaces/example/code-module/target/jacoco.exec
Question
Instead of adding such a dummy test class, is there a way to configure maven-surefire-plugin to generate the jacoco stuff always?
Maybe something I can put in the parent pom, so it will automatically work for all child-module without tests.

"Build step 'Invoke top-level Maven targets' marked build as failure" error

Good day! I would like to ask about the error that I'm encountering in Jenkins:
"Build step 'Invoke top-level Maven targets' marked build as failure"
I'm trying to run a selenium script (with JMeter script inside) in Jenkins. I'm getting a BUILD SUCCESS in console output in Jenkins but it marks the job failed because of that error. Kindly see below the console output:
Running TestSuite
Start: 11/04/2016 5:19:29 PM
RawConfigFileScenario3 is created
11/04/2016 5:19:49 PM [PASSED] No Error encountered on the Jmeter Script
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 23.962 sec - in TestSuite
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 48.165 s
[INFO] Finished at: 2016-11-04T17:19:50+08:00
[INFO] Final Memory: 14M/137M
[INFO] ------------------------------------------------------------------------
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
I also tried to run the same script in Eclipse and I'm getting a SUCCESS result. Please see below the logs:
Running TestSuite
Start: 11/04/2016 4:26:26 PM
RawConfigFileScenario3 is created
11/04/2016 4:26:41 PM [PASSED] No Error encountered on the Jmeter Script
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 17.739 sec - in TestSuite
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.743 s
[INFO] Finished at: 2016-11-04T16:26:41+08:00
[INFO] Final Memory: 13M/136M
[INFO] ------------------------------------------------------------------------
I would like to ask for your guidance regarding this matter. Thank you in advance for the answers. :)
i have encounter this problem. and i just change the sdk configuration from java8 to java7.
hope this can help you.

Error while executing test via Jenkins

I'm having this error while running my test suite from jenkins and when i run in eclipse via Maven it's working fine,
I'm using the same pom.xml for jenkins which is giving this error:
Running TestSuite
INFO [main] (BrowserManager.java:124) - Connecting to http://chromedriver.storage.googleapis.com/ to check lastest chromedriver release
INFO [main] (BrowserManager.java:112) - Latest driver version: 2.9
INFO [main] (Downloader.java:56) - Binary driver previously downloaded /var/lib/jenkins/.m2/repository/webdriver/chromedriver/linux64/2.9/chromedriver
INFO [main] (Downloader.java:60) - Exporting webdriver.chrome.driver as /var/lib/jenkins/.m2/repository/webdriver/chromedriver/linux64/2.9/chromedriver
Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 2.904 sec <<< FAILURE! - in TestSuite
Setup(webautomation.GetApp) Time elapsed: 2.218 sec <<< FAILURE!
java.lang.NoClassDefFoundError: org/openqa/selenium/ElementNotSelectableException
at webautomation.GetApp.Setup(GetApp.java:57)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.ElementNotSelectableException
at webautomation.GetApp.Setup(GetApp.java:57)
Results :
Failed tests:
webautomation.GetApp.Setup(webautomation.GetApp)
Run 1: GetApp.Setup:57 ยป NoClassDefFound org/openqa/selenium/ElementNotSelectableExce...
Run 2: PASS
Tests run: 3, Failures: 1, Errors: 0, Skipped: 2
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.671 s
[INFO] Finished at: 2016-10-06T17:27:37+05:00
[INFO] Final Memory: 26M/200M
[INFO] ------------------------------------------------------------------------

NoClassDefFoundError when hudson runs a maven project

I have a project for running tests. It's a maven project which uses Selenium. It runs correctly when launched locally, but from the Hudson platform, it throws NoClassDefFoundError:
Parsing POMs
[elsevier-selenium] $ "C:\Program Files\Java\jdk1.7.0_25/bin/java" -Xmx1024m -cp E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven-agent-1.353.jar;E:\maven\boot\classworlds-1.1.jar hudson.maven.agent.Main E:\maven E:\hudson\war\WEB-INF\lib\remoting-1.353.jar E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven-interceptor-1.353.jar 1753 E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven2.1-interceptor-1.2.jar
<===[HUDSON REMOTING CAPACITY]===>channel started
Executing Maven: -B -f E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\pom.xml integration-test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building selenium-elsevier
[INFO] task-segment: [integration-test]
[INFO] ------------------------------------------------------------------------
[INFO] [compiler:testCompile {execution: default}]
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\target\test-classes
[INFO] [site:attach-descriptor {execution: default-attach-descriptor}]
[INFO] [failsafe:integration-test {execution: default}]
[INFO] Failsafe report directory: E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\target\failsafe-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running fr.elsevier.tests.disponibilite.SearchTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.203 sec <<< FAILURE!
fr.elsevier.tests.disponibilite.SearchTest Time elapsed: 0.203 sec <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class fr.elsevier.tests.BaseSelenium
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.apache.maven.surefire.report.SmartStackTraceParser.getClass(SmartStackTraceParser.java:63)
at org.apache.maven.surefire.report.SmartStackTraceParser.<init>(SmartStackTraceParser.java:53)
at org.apache.maven.surefire.common.junit4.JUnit4StackTraceWriter.smartTrimmedStackTrace(JUnit4StackTraceWriter.java:72)
[...]
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
SearchTest extends BaseSelenium.
Which means it cannot even find a class in my source folder. The project structure is like this:
src/
fr.elsevier.tests/
disponibilite/
SearchTest.java
BaseSelenium.java
pom.xml
Why does the build generates these NoClassDefFoundErrors and how to fix it?
Try using -e or -X command line argument in local and hudson build. Then try to compare the classpath of the java processes launched.
You can then actually figure out which part of maven lifecycle threw the exception with better stacktrace.

No line-after-line output from #Test block when running JUnit test with maven

I have a Junit test running under maven with
mvn clean test -Dtest=MyTest
The output looks as following:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building autotest-tests
[INFO] task-segment: [clean, test]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory workspace/tests/target
[INFO] [compiler:testCompile {execution: compile tests}]
[INFO] Compiling 76 source files to workspace/tests/target/test-classes
[INFO] [surefire:test {execution: run tests}]
[INFO] Surefire report directory: workspace/tests/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='classes', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false
Output of #Before block...
Output of #Before block...
Output of #Before block...
Then the output stops. Any line by line output to command line from the #Test block is held back I see them on the console only after the test is over:
Output of #Test block...
Output of #Test block...
Output of #Test block...
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 75.564 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 18 seconds
[INFO] Finished at: Mon Feb 06 12:22:22 CET 2012
[INFO] Final Memory: 24M/302M
[INFO] ------------------------------------------------------------------------
I did work before, i.e. I was getting a line by line test output on the console as the test was proceeding. Since some time (maybe an update) stopped.
Any ideas what is the reason behind it?
The surefire plugin write the output to a file by default. This can be controlled with the useFile option, which can be set from the command line:
-Dsurefire.useFile=false
It is also possible to set this as a default value in your settings.xml by creating and activating a profile:
<profiles>
<profile>
<id>sureFire.useFile</id>
<properties>
<surefire.useFile>false</surefire.useFile>
</properties>
</profile>
</profile>
<activeProfiles>
<activeProfile>sureFire.useFile</activeProfile>
</activeProfiles>

Resources