Running Cucumber tests directly from executable jar

前端 未结 2 638
日久生厌
日久生厌 2020-12-05 07:52

I have a project with cucumber and maven also I am using the JUnit.

I am able to run and build my project successfully from Eclipse.

Now I want to run the t

相关标签:
2条回答
  • 2020-12-05 08:34
    @SpringBootApplication
    public class Application {
    
        public static void main(final String[] args) throws Throwable {
            // SpringApplication.run(TestApplication.class, args);
            JUnitCore.main(CucumberTest.class.getCanonicalName());
        }
    
    }
    
    0 讨论(0)
  • 2020-12-05 08:50

    I would divide the problem you are thinking of in two parts.

    • Create an executable jar
    • Run Cucumber from your own main method

    Creating an executable jar using Maven can be done in different ways. One way of doing it is described here: http://www.thinkcode.se/blog/2011/03/05/create-an-executable-jar-from-maven

    It is a small example that only focuses on executing something from a command line like this:

    java -jar executable-example.jar

    The example contains all dependencies. They are all bundled in the same jar. No need for any additional jars.

    Next step would be to execute Cucumber from a main method. My approach would be to write a main that executes the Cucumber main method used for the command line version of Cucumber. The main method used to run cucumber from a command line lives in the cucumber-java library. You will find it at cucumber.api.cli.Main

    Running a main method from another main method is done like this:

    public static void main(String[] args) throws Throwable {
        String[] arguments = {"foo", "bar"};
        cucumber.api.cli.Main.main(arguments);
    }
    

    where arguments are the command line arguments you always want to execute Cucumber with.

    Given these two steps, you should be able to execute Cucumber from your own executable jar wherever you are able to execute a jar at all.

    Notice that you are mixing library version for Cucumber in your pom. I would use the latest version of all libraries. Compare cucumber-java, cucumber-testng and cucumber-junit. The latest Cucumber version is 1.2.4. I would use it for all of them.

    More information about running Cucumber from a command line can be found here: https://cucumber.io/docs/cucumber/api/#from-the-command-line

    0 讨论(0)
提交回复
热议问题