如何从其他主要方法调用CucumberRunner类 [英] How to invoke the Cucumber runner class from a different main method

查看:78
本文介绍了如何从其他主要方法调用CucumberRunner类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用命令行界面的新手.因此,我只想知道如何使用CLI技术调用黄瓜的跑步者类.

I'm new to using Command Line Interface. So I just have a question on how to invoke the runner class of the cucumber using CLI technique.

我有一个包含主要方法的Java程序.当测试人员传递作为测试用例的参数时,它将获取功能文件. Java程序调用定制的API,该API将获取正确的功能文件.

I have a Java program which contains a main method. When testers pass the argument which is test case, it will fetch the feature file. The java program invoke a custom made API which will fetch the correct feature file.

接下来,我将不得不调用CucumberRunner类来执行测试用例.我需要将此特殊功能文件作为参数传递.两个问题,我们可以从不同的main方法调用Runner类吗?我做了一些研究,但找不到具体答案. 两个问题,

Next I'll have to invoke the Cucumber runner class to execute the test case. I need to pass this particular feature file as the argument. Two questions, Can we invoke the runner class from a different main method. I did some research and I was not able to find a concrete answer. Two questions,

  1. cucumber.api.cli.Main.main(arguments);因此,如何指定跑步者课程的jar位置.

  1. cucumber.api.cli.Main.main(arguments); So how do i specify the jar location of my runner class.

`FeatureFileCreation.main("xxxxx"); -获取正确功能文件的API String []参数= {-","}; cumul.api.cli.Main.main(参数);

`FeatureFileCreation.main("xxxxx"); - API that fetches the right feature file String[] arguments = {"-", ""}; cucumber.api.cli.Main.main(arguments);

  • 如何指定罐子所在的位置?如何传递功能文件?`

我应该在Runner类中创建一个主方法吗?为了使用CLI,因为我需要创建一个可运行的jar.我的跑步者课上应该有一个主要方法.

Should I create a main method in the runner class, something like this? For the sake of using CLI,Since I need to create a runnable jar. I should have a main method in my runner class.

`

@RunWith(Cucumber.class)
@Cucumber.Options(features="C:/Users/IBM_ADMIN/Desktop/CRAutomation/CR Regression1/src/My.feature",glue={"bell.canada.step.definition"})

public class AutomationRunnerAction { 

    public void main(){
    }
}`

请注意,获取正确的功能文件是1个Java API.我将从一个Java程序的一种主要方法调用该API.具有步骤定义和方法的运行器类是diff java程序.

Please note that, Getting the right feature file is 1 java API. I will invoking that API from one main method of one java program. The runner class with step definition and methods are a diff java program.

推荐答案

不幸的是,接受答案不正确.如果您查看

Unfortunately the accept answer is not correct. If you look at the source of Main.main() you'll notice that it contains: System.exit(exitstatus) which terminates the system.

以编程方式运行命令行的正确方法是像这样使用Main.run():

The proper way to run the commandline programatically would be to use Main.run() like this:

String [] argv = new String[]{ "-g","","./src/main/java/featureDetails/Testing.feature"};
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
byte exitstatus = Main.run(argv, contextClassLoader);

这篇关于如何从其他主要方法调用CucumberRunner类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆