Cucumber tests configured in main method are not executing from jar file - cmd

I have a BDD maven project for API testing. I want to execute the cucumber tests independently by/from anywhere. To do this I required two things:
1. A jar (I have built it via assembly plugin and maven-jar-plugin also )
2. A class having main() method OR Runner classes. (I have defined both in my framework)
Runner Class:
3. While running the command in cmd it is giving the error
java -jar dealflow-bdd-1.0.4-SNAPSHOT.jar
Note: By following the approach discussed in this question
Running Cucumber tests directly from executable jar
I am able to create the jar by maven-assembly-plugin but the error seems to change. Now by running
java -jar dealflow-bdd-1.0.4-SNAPSHOT.jar
it is giving this
Comment: Tests are running if I run the main() method directly from the IDE itself or Run the Runner class

Related

Run tests located within a fat maven jar?

I have a maven project which is a test harness including tests.
The tests can be run using surefire, within intelliJ. And the IDE states the command line it is running in order to do this:
java
-Dmaven.multiModuleProjectDirectory=...
"-Dmaven.home=...
"-Dclassworlds.conf=...
"-Dmaven.ext.class.path=...
"-javaagent:...
-Didea.version=...
install
If I put the jar on another machine, and wish to run the tests contained within it (ideally with surefire plugin) should I be aiming to construct a similar command line as to the above, or run something like mvn test {jar name} or mvn surefire:test {jar name}

Maven how to show Junit test like on Eclipse IDE

I would like to run Junit tests via maven command like having the test result
with the same graphical message that I can see using Eclipse IDE.
For example, if I run Junit test via Eclipse I can see this tree image:
But, if I run the same tests via maven command line, I can see only the grand total result without details.
For example:
There is a way to run maven command line tests and receive the test result like Eclipse IDE?
I use surefire plugin on my project.
Thanks in advance.

Importing tests from another project using Gradle

I have a microservice that has a sub-folder full of integration tests written in Groovy. These tests basically make a bunch of REST calls. Gradle is configured to produce a JAR for these tests like so:
//Explicitly add the integration tests to the JAR
jar {
from sourceSets.test.output
}
Unzipping the JAR shows the Groovy tests that were in the project. That seems good so far.
Now, there is a larger project that I want to use (in a different git repo) that will import these tests and run them. The plan is to import several other test suites in a similar fashion and build a sort of uber-test project. This project can import the test JAR as a dependency as testCompile. I can see the JAR in the SourceSets using IDEA's gradle plugin. However, I can't get the tests to run using gradle test.
How can I modify the uber-test project to execute these imported test?

Invoking maven from inside an uber jar using pom.xml located inside jar

I am running a set of tests using junit and I have created a maven project for it. I use the surefire plugin to run the tests. I wanted to package this project as a self executable jar for the sake of convenience.So I placed all of test classes in the src/main/java directory as recommended for using the maven shade plugin for generating an uber jar. I created a class with a main method and use maven invoker to execute my tests.
The tests get executed perfectly when I use my ide to run the main method. However, after I package it as a jar , the invoker is unable to locate the pom.xml. If I place a copy of the pom.xml in the same directory as the jar, maven is invoked but it is unable to execute the tests as surefire is unable to locate the tests.
I would love to know if there is a solution for this or if there is a better approach towards trying to achieve my goal.
#khmarbaise and everyone else trying to help me , let me describe my scenario a little more in detail.
Lets take any api , for example , lastfm api, I would be writing classes for each api end point and every method in each class would be a test. I use junit to execute the tests. I use a junit wrapper called serenity bdd that helps me structure my tests and generate aggregate reports. The maven goal serenity:aggregate would generate an aggregated report of all tests. I am using the maven invoker to run tests using surefire plugin and then aggregate the tests using serenity. In my eclipse project I simply create a maven run configuration and provide the maven goals. Or else I would use the terminal to run maven from my project base directory.
Apart from my class file, I have several resources, like csv files which are inputs for parametric tests a log folder where all log files that are generated get saved and other sample files for testing file upload apis. I felt that it would be simple to package all of this as a jar and let my developers add this jar as a dependency and run a simple script which runs the jar each time they create and deploy a build. Getting the pom file for invoking maven was trivial in case of eclipse or the command line but not so straight forward when its inside of a package.

TestNG execute compiled tests in jar file

I have a testNG test class which runs fine, but when i package it into a jar file with test files included, i am unable to run the tests from it. The jar file contains the test.class file in it. When i invoke the test from maven it returns "no tests to run".
Any suggestion on how to run a test class within a jar using testNG?
Can you open the jar file with winrar and see if everything is packed there?
Also, is testng your application entry point? What happens when you write:
java -jar yourjar.jar
in console? You should see testng output.
Also, are you sure your parameter xml file is pointing to the right class and that it works?
Are your classes in the jar file? the classes with your tests? Please check that with winrar to see the jar content.
I think that with this checklist your tests should run.

Resources