我在子目录中有一个简单的测试运行程序类: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类。而且TestRunner
中的主方法永远不会被Cucumber调用。