Manisha Awasthi
Manisha Awasthi

Reputation: 479

Is there any way I can create a "jar" file to run my cucumber tests?

My Feature files resides in src/test/resources and testrunner class resides in src/test/java as per default cucumber-jvm set up.

I want to package this project in a jar file so that when I execute the jar, my tests should run.

How should I do it?

Upvotes: 3

Views: 3730

Answers (1)

Dean Marsden
Dean Marsden

Reputation: 192

After a lot of tinkering around I think I may have a solution.

You would have two files (Sorry if my jargon is a bit off, I'm new to this too) A Step Definition file and a Test Runner file. Make sure in your Test Runner file you have a main method

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

So that is ends up looking something like this:

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

Run it as a Java Application.

Once that is done, you can now click it and export it as a Runnable Jar File. In the Launch configuration after selecting the Runnable Jar File option, choose your TestRunner from the drop down if it hasn't been selected and then select the appropriate Library handling. (I chose Extract required libraries to generate JAR) And an appropriate file destination.

Then click finish.

In my Test Runner java file I also added this:

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

This dumps the test into two usable files, JSON and XML, where you can view the details of your test.

I hope this helps.

Upvotes: 4

Related Questions