将TestNG与Java集成
有没有办法将cucumber与现有的testng项目集成?目前,在我们的项目中,我们正在使用带有页面对象模型的testng。现在我们决定把黄瓜也包括在内。但我认为我们不能,因为cucumber使用功能文件,我们可以有n个场景。但是testng是基于@test方法运行的。将TestNG与Java集成,java,selenium,cucumber,testng,Java,Selenium,Cucumber,Testng,有没有办法将cucumber与现有的testng项目集成?目前,在我们的项目中,我们正在使用带有页面对象模型的testng。现在我们决定把黄瓜也包括在内。但我认为我们不能,因为cucumber使用功能文件,我们可以有n个场景。但是testng是基于@test方法运行的。 所以,让我知道我们是否可以集成cucumber+testng,如果可以的话,我们如何使用cucumber运行每个@test方法。使用testng runner运行cucumber场景/功能是可能的,它会增加价值,但反过来就不行了
所以,让我知道我们是否可以集成cucumber+testng,如果可以的话,我们如何使用cucumber运行每个@test方法。使用testng runner运行cucumber场景/功能是可能的,它会增加价值,但反过来就不行了。您希望通过使用cucumber runner运行TestNG实现什么?如果您想在现有TestNG测试中使用描述性步骤级报告,可以开始使用。是。您可以集成JVM+testng 您可以在TestNG的@Test方法中使用cumberjvm。不要使用Cucumber API的Main.Main,因为末尾有一个System.exit(0)。相反,您可以使用Main.run黄瓜。 在测试方法中调用run方法
Main.main(new String[]{"-g", "package", "path of feature file"}, ClassLoader.getClassLoader);
run方法需要一个类加载器,因此如果需要,可以生成自己的类加载器
public static byte run(String[] argv, ClassLoader classLoader) throws IOException {
RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList(argv)));
ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
runtime.run();
return runtime.exitStatus();
公共静态字节运行(字符串[]argv,类加载器类加载器)引发IOException{
RuntimeOptions RuntimeOptions=newruntimeoptions(newarraylist(asList(argv)));
ResourceLoader ResourceLoader=新的多加载器(类加载器);
ClassFinder ClassFinder=new resourceLoader ClassFinder(resourceLoader,classLoader);
运行时=新运行时(resourceLoader、classFinder、classLoader、runtimeOptions);
runtime.run();
返回runtime.exitStatus();
}
您还可以创建自己的类加载器来运行main方法 你已经知道答案了,你必须有功能文件来处理黄瓜看看这个。。。基本上,您必须将代码从测试方法移动到步骤定义。如果要继续使用现有的testng方法,插入cucumber的逻辑或好处是什么?