Java 在Maven中使用Cucumber从Main运行Junit测试

Java 在Maven中使用Cucumber从Main运行Junit测试,java,maven,selenium,junit,cucumber,Java,Maven,Selenium,Junit,Cucumber,我在一个子目录中有一个简单的testrunner类:src/test/java @RunWith(Cucumber.class) //@Feature("my/package/**/*.feature") @CucumberOptions( features= {"src/test/java/multiTest/Login_Logout.feature"} , glue={"stepDefs"} , monochrome = true , plugin = {"pretty"} ) pu

我在一个子目录中有一个简单的testrunner类:src/test/java

@RunWith(Cucumber.class)
//@Feature("my/package/**/*.feature")
@CucumberOptions(

  features= {"src/test/java/multiTest/Login_Logout.feature"}
, glue={"stepDefs"}
, monochrome = true
, plugin = {"pretty"}
)

public class TestRunner {
public static void main(String[] args) throws Exception {    
    System.out.println("This is a test");
    JUnitCore.main("multiTest.TestRunner");    
}
}
从我的主文件src/main/java中,我想调用这个TestRunner类。最终,这将被配置为从主线程获取用户输入并将其传递到测试线程。然而,这个类的最后一行抛出编译错误

public static void main(String[] args) throws Exception {
     JFrame frame = new JFrame("QA for EDI");
    // Setting the width and height of frame
    frame.setSize(500, 450);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    /* Creating panel. This is same as a div tag in HTML
     * We can create several panels and add them to specific 
     * positions in a JFrame. Inside panels we can add text 
     * fields, buttons and other components.
     */
    JPanel panel = new JPanel();    
    // adding panel to frame
    frame.add(panel, BorderLayout.CENTER);
    TestRunner.run(TestRunner.class);
}

有没有办法实现我的目标

TestRunner
没有静态run()方法,因此会出现错误。run()属于Thread类

通过此设置,您试图实现什么目标?如果要传递任何数据,请将其直接放入要素文件中。这就是Cucumber中场景的全部要点。将所有要测试的不同内容作为单独的场景放进去


无论如何,要使用
TestRunner
类执行Cucumber特定的任何操作,您需要使用
RunWith
注释中提到的Cucumber TestRunner类。Cucumber永远不会调用
TestRunner
中的main方法。

TestRunner
没有静态run()方法,因此会出现错误。run()属于Thread类

通过此设置,您试图实现什么目标?如果要传递任何数据,请将其直接放入要素文件中。这就是Cucumber中场景的全部要点。将所有要测试的不同内容作为单独的场景放进去


无论如何,要使用
TestRunner
类执行Cucumber特定的任何操作,您需要使用
RunWith
注释中提到的Cucumber TestRunner类。Cucumber将永远不会调用
TestRunner
中的主要方法。

我正在尝试使这个程序可移植,这样测试就可以通过GUI运行,而不需要任何人触摸代码。其他人将编写并指定功能文件,这样我的程序将只是步骤库和测试运行程序;将再次调用TestRunner并点击Cucumber注释。用户将提供什么类型的输入?浏览器类型、功能文件和用户凭据。请查看Cucumber jvm的CLI runner。我正在尝试使此程序可移植,以便测试可以通过GUI运行,而无需任何人触摸代码。其他人将编写并指定功能文件,这样我的程序将只是步骤库和测试运行程序;将再次调用TestRunner并点击Cucumber注释。用户将提供什么类型的输入?浏览器类型、功能文件和用户凭据。请查看Cucumber jvm的CLI runner。