Jenkins is unable to execute Cucumber tests using Maven Surefire, Spring Boot and JUnit5 - spring-boot

I am using spring-boot-starter-parent:2.2.6.RELEASE and cucumber-java8:5.6.0 to execute e2e tests using Cucumber Runner/Spring Boot/JUnit5/Maven Surefire. I have installed latest Jenkins Community LTS v2.222.1 on a Linux VM and connected my laptop as a slave.
When I execute the tests on my laptop using IDE / command prompt it works fine (using mvn clean test). However same tests are not running when triggered from Jenkins. It's bit confusing since I am using same config/tools.
Jenkins Console O/P:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Jenkins\workspace\Sanity\core\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # project-core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportParser parseForFeature
INFO: File {0} does not contain features
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportParser parseJsonFiles
INFO: File 'C:\Users\User\AppData\Local\Temp\2\cucumber5203280546924184867.json' contains 0 features
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportBuilder generateErrorPage
INFO: Unexpected error
net.masterthought.cucumber.ValidationException: Passed files have no features!
...
IDE Console O/P:
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Code\project\core\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # project-core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.x.y.z.CucumberTests
2020-04-07 13:22:52.330 INFO --- [ main] .b.t.c.SpringBootTestContextBootstrapper : Neither #ContextConfiguration nor #ContextHierarchy found for test class [com.x.y.z.stepdefs.LogVerificationSteps], using SpringBootContextLoader
...
CucumberTests.java:
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "de.monochromata.cucumber.report.PrettyReports:target"},
features = "src/test/resources/features")
public class CucumberTests {
}
This is multi-module maven project, the features are available under:
root
\__core
\__src/test/resources/features/*
So basically in Jenkins features/tests are not being run at all - why is it happening, any idea folks?

Related

Run maven project without testng from Jenkins

I am working on selenium and have created a maven project with user creation and user registration in Eclipse. There is no TESTNG involved in this implementation.
Now, I have created a maven job in Jenkins and configured the pom.xml path and goal set as 'clean install'.
While running this maven job from Jenkins, the build is success but none of the scripts from Eclipse ran for user creation and user registration.
I am seeing the below in the console output in Jenkins against the Job:
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # GDPortalDemo ---
[INFO] Surefire report directory: C:\RSV\Selenium\GDPortalDemo\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[JENKINS] Recording test results
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # GDPortalDemo---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\RSV\Selenium\GDPortalDemo\target\GDPortalDemo-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # GDPortalDemo---
[INFO] Installing C:\RSV\Selenium\GDPortalDemo\target\HybridSauceDemo-0.0.1-SNAPSHOT.jar to C:\Users\daisy\.m2\repository\GDPortalDemo\GDPortalDemo\0.0.1-SNAPSHOT\GDPortalDemo-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\RSV\Selenium\GDPortalDemo\pom.xml to C:\Users\daisy\.m2\repository\GDPortalDemo\GDPortalDemo\0.0.1-SNAPSHOT\GDPortalDemo-0.0.1-SNAPSHOT.pom
Earlier, I had sure-fire plugin in my pom.xml. I have removed that plugin from pom.xml now and then executed the job.
Can we run a maven job from Jenkins that doesn't have testng tests? In my project, we are not going to use testng. Appreciate any help on this please.

Is there a way to porsue with maven build after running wildfly:run goal?

I would like to complete Maven build lifecycle after wildfly:run goal's execution.
The fact is that wildfly:run goal starts a standalone application server and from that point the CLI shows Wildfly's Log messages only.
[INFO] --- wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:run (default) # PrimeFaces1 ---
[WARNING] The POM for org.wildfly.plugins:wildfly-plugin-core:jar:2.1.0.Beta1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] JAVA_HOME : C:\Program Files\Java\jdk1.8.0_201\jre
[INFO] JBOSS_HOME: C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\wildfly-18.0.1.Final
[INFO] JAVA_OPTS : -Xms64m -Xmx512m -Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Djboss.modules.system.pkgs=org.jboss.byteman
[INFO] Server is starting up. Press CTRL + C to stop the server.
[INFO] JBoss Threads version 2.3.3.Final
[INFO] JBoss Remoting version 5.0.12.Final
[INFO] XNIO version 3.7.2.Final
[INFO] XNIO NIO Implementation Version 3.7.2.Final
[INFO] ELY00001: WildFly Elytron version 1.9.1.Final
13:04:25,585 INFO [org.jboss.modules] (main) JBoss Modules version 1.9.1.Final
13:04:26,228 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.11.Final
13:04:26,248 INFO [org.jboss.threads] (main) JBoss Threads version 2.3.3.Final
13:04:26,472 INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: WildFly Full 18.0.1.Final (WildFly Core 10.0.3.Final) starting
13:04:27,800 INFO [org.wildfly.security] (ServerService Thread Pool -- 28) ELY00001: WildFly Elytron version 1.10.4.Final
Actually I would like to run next goals but the server takes control of the CLI
Besides, in the pom.xml, I've tried to sobstitute wildfly:run with the wildfly:deploy goal, which deploy the artifact on the local JBOSS server(already started), And in this case the maven build goes on until the end.
[INFO] --- maven-war-plugin:2.2:war (default-war) # PrimeFaces1 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [PrimeFaces1] in [C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\PrimeFaces1-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\src\main\webapp]
[INFO] Webapp assembled in [128 msecs]
[INFO] Building war: C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces1\target\PrimeFaces1-1.0-SNAPSHOT.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] <<< wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) < package # PrimeFaces1 <<<
[INFO]
[INFO]
[INFO] --- wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) # PrimeFaces1 ---
[INFO] JBoss Threads version 2.3.3.Final
[INFO] JBoss Remoting version 5.0.12.Final
[INFO] XNIO version 3.7.2.Final
[INFO] XNIO NIO Implementation Version 3.7.2.Final
[INFO] ELY00001: WildFly Elytron version 1.9.1.Final
[INFO]
[INFO] --------------------< com.mkyong.core:PrimeFaces2 >---------------------
[INFO] Building PrimeFaces2 1.0-SNAPSHOT [3/3]
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] >>> wildfly-maven-plugin:2.1.0.Beta1-SNAPSHOT:deploy (default-cli) > package # PrimeFaces2 >>>
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # PrimeFaces2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Consul19\eclipse-workspace\MultiRunTest\PrimeFaces2\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # PrimeFaces2 ---
[INFO] Nothing to compile - all classes are up to date
As you can see in this case the deploy goal doesn't "lock" the CLI but the build process still continues until the end
This behaviour is expected for the wildfly:run command, you're supposed to interrupt the server from the outside once you're done testing. Quoting the goal's documentation,
This goal will block until cancelled or a shutdown is invoked from a management client.
If that doesn't suit you, you can instead use wildlfy:start followed by wildfly:deploy.

Run single method from commandline using Maven and Jnunit

I am tryinf a apporach to run a single test method from commandline using maven or either Junit. My project is build in Junit Framework with Maven.
I have parallel execution in place to run methods in parallel. When I try to run this from commandline, it is still running all testmenthds in parallel.
mvn -Dtest=<Classname>#<testmethodname> test
Would anyone help, how to acheive to run single testmethod or sepcific test methods from commandline.
Versions:
junit - 4.9
maven-compiler-plugin - 2.5.1
maven-surefire-plugin - 2.8
this is log for refrence
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <ProjectName> 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.8:test (default-test) # ---
[INFO] Surefire report directory: C:\Automation\......\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='methods', perCoreThreadCount=false, threadCount=6, useUnlimitedThreads=false
Destroying 1 processes
Destroying process..
Destroyed 1 processes
Terminate batch job (Y/N)?
Spelling mistake spotted buddy, correct one is -Dtest and not -DTest
mvn -Dtest=<Classname>#<testmethodname> test
Additionally, as you are already running multiple tests in parallel, you can also use below mentioned pattern to execute like test methods.
Example:
mvn -Dtest=Classname#testMethod1+testMethod2+testMethod3 test
Enjoy... ;)
The surefire parameter for excuting a single test is test not Test so you should invoke the following Maven command:
mvn -Dtest=<ClassName>#<TestMethodName> test
For example, given ...
A test FooTest with a test method: foo()
A test BarTest with a test method: bar()
... you could invoke the following:
Run FooTest.foo()
mvn -Dtest=FooTest#foo test
Run FooTest.foo() and BarTest.bar()
mvn -Dtest=FooTest#foo,FooTest#bar test

How do I set the port using maven?

I'm using Maven from the command line on Windows, but I don't need to necessarily change the port from the command line specifically.
Running the command
mvn -Djetty.http.port=8000 exec:java
results in the following output:
[INFO] Scanning for projects...
[WARNING] The project com.google.apis-samples:oauth2-cmdline-sample:jar:1
uses prerequisites which is only intended for maven-plugin projects but not
for non maven-plugin projects. For such purposes you should use the maven-
enforcer-plugin. See https://maven.apache.org/enforcer/enforcer-
rules/requireMavenVersion.html
[INFO]
[INFO] ---------------------------------------------------------------------
---
[INFO] Building Example for the OAuth2 API using JSON and OAuth 2.0 1
[INFO] --------------------------------------------------------------------
----
[INFO]
[INFO] >>> exec-maven-plugin:1.1:java (default-cli) > validate # oauth2-
cmdline-sample >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.1:java (default-cli) < validate # oauth2-
cmdline-sample <<<
[INFO]
[INFO]
[INFO] --- exec-maven-plugin:1.1:java (default-cli) # oauth2-cmdline-sample
---
Jun 19, 2017 5:09:53 PM
com.google.api.client.util.store.FileDataStoreFactory
setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody:
C:\Users\roxlala\.store\oauth2_sample
Jun 19, 2017 5:09:53 PM
com.google.api.client.util.store.FileDataStoreFactory
setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner:
C:\Users\roxlala\.store\oauth2_sample
2017-06-19 17:09:53.229:INFO::Logging to STDERR via
org.mortbay.log.StdErrLog
2017-06-19 17:09:53.229:INFO::jetty-6.1.26
2017-06-19 17:09:53.259:INFO::Started SocketConnector#localhost:1871
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=<my-id>.
googleusercontent.com&redirect_uri=http:
//localhost:1871/Callback&response_type=code&scope=https://www.googleapis.
com/auth
/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email
Attempting to open that address in the default browser now...

Jenkins build fails no error

I am quite new when it comes to Jenkins and I am trying to setup a continuous integration environment for our workspace. I am running Jenkins locally on a Windows client - solely for testing purposes - but cannot seem to find the error that is causing the build to fail. All I want to do is trigger an automatic build that will compose the .war file.
Here is the generated output from Jenkins:
<===[JENKINS REMOTING CAPACITY]===>channel started
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
Executing Maven: -B -f C:\Program Files (x86)\Jenkins\jobs\POSIOS\workspace\XudoxWS\src\main\XudoxWS\pom.xml mvn install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building XudoxWS WebServer 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.116s
[INFO] Finished at: Mon Oct 14 18:22:33 CEST 2013
[INFO] Final Memory: 7M/154M
[INFO] ------------------------------------------------------------------------
I can confirm that I can locally build the project without any issues. I am using Maven.
Thanks in advance for your offered help.
Seems like you've set the following as goals and options:
mvn install -Dmaven.test.skip=true
You shouldn't include the mvn executable, then it'll work just fine.

Resources