Is there a way to create a "jar" file to run cucumber tests?

My function files are in src / test / resources and the testrunner class is in src / test / java by default for oucc-jvm setup.

I want to package this project into a jar file so that when the jar is executed my tests will run.

How should I do it?

+3


source to share


1 answer


After much consideration, I think I might have a solution.

You will have two files (sorry if my jargon is a little off, I'm not familiar with this either) A step definition file and a test run file. Make sure you have a main method in your Test Runner file

public static void main(String[] args) throws Exception {                    
    JUnitCore.main(
      "PackageName.Filename");    
}

      

So it looks something like this:

public class TestRunner {
    public static void main(String[] args) throws Exception {                    
        JUnitCore.main(
          "cucumberTest.TestRunner");    
    }
}

      

Run it as Java application.



Once that's done, you can click it and export it as a Runnable Jar file. In the run configuration, after selecting the Runnable Jar File option, select TestRunner from the drop-down list if it was not selected, and then select the appropriate library handling. (I selected Extract the required libraries to generate the JAR) And a suitable file destination.

Then click Finish.

In my Test Runner java file I also added the following:

@CucumberOptions(
        features = "Feature"
        ,glue={"stepDefinition"}
        ,plugin={"pretty",
        "json:C:/EclipseWorkspace/ProjectName/cucumber.json",
        "junit:C:/EclipseWorkspace/ProjectName/cucumber.xml"}
        )

      

This dumps the test to two available files: JSON and XML, where you can view your test details.

Hope this helps.

+3


source







All Articles