简体   繁体   中英

Running cucumber test file from application button

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();
            }
        }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM