Running cucumber test file from application button

498 views Asked by At

I've set up a test file in src/main/java with my cucumber annotations containing class A, as well as a test file extending class A in src/test/java with the following annotation on class B:

        @ContextConfiguration(locations = {"classpath:META-INF/application-config.xml", "classpath:META-INF/overrule.xml" })

This is working fine when I do a maven clean install. What I would like to achieve though is being able to run a feature file through the cucumber setup of class A and see its output. So far I've managed to find a method which should allow me to run the cucumber test, but I can't seem to figure out what its arguments should be. Could anyone provide me with an example of how to implement the function cucumber.api.cli.Main.run()?

        @Override
        public void buttonClick(final ClickEvent event) {
            try {
                final String[] arguments = {"foo", "bar" };
                cucumber.api.cli.Main.run(arguments, ClassLoader.getSystemClassLoader());
            } catch (final Throwable e) {
                e.printStackTrace();
            }
        }
1

There are 1 answers

1
Thomas Sundberg On

I would invoke the command line version using cucumber.api.cli.Main.main(args);

where args is a String array with the parameters set. I would not use the run command you refer to.

The documentation describes all available options.

Another source may be the getting started project supplied by the Cucumber team: https://github.com/cucumber/cucumber-java-skeleton

It may be of specific interest to look into the Ant build script https://github.com/cucumber/cucumber-java-skeleton/blob/master/build.xml to see what arguments they supply to Cucumber.