我正在使用 eclipse 2018-09 (4.9.0) 和 testng 插件(版本 6.14.0.201802161500)。我创建了一个 Maven 项目来从教程中学习 testng。我想在 Eclipse 中运行 testng 工厂方法,但运行菜单中没有“testng”选项。我如何让它运行工厂?
我的代码:
package com.learn.classes;
import org.testng.annotations.Test;
//run with testng is present for this.
public class SimpleTest {
@Test
public void simpleTest() {
System.out.println("Simple test Method");
}
}
package com.learn.factory;
import org.testng.annotations.Factory;
import com.learn.classes.SimpleTest;
//run with testng is NOT present for this.
public class SimpleTestFactory {
@Factory
public Object[] factoryMethod() {
return new Object [] {new SimpleTest(), new SimpleTest()};
}
}
解决方案 :为上述类或方法创建一个 xml 套件,并使用 testng 运行它。
前任。 myfactory.xml
<suite name="Factorty Methods" verbose="1">
<test name="My factory method">
<classes>
<class name="factory.SimpleTestFactory" />
<methods>
<include name="factoryMethod" />
</methods>
</classes>
</test>
</suite>
您看到此行为的原因是因为 TestNG eclipse 插件会查找任何测试方法(至少一个用@Test
注解)在类中,然后通过右键单击启用该上下文选项。
在工厂的情况下(就像你的示例代码如何SimpleTestFactory
看起来像),没有测试方法。这就是为什么它禁用Run As > TestNG test
option.
因此,替代方案之一是基本上创建一个套件 xml 文件,添加对SimpleTestFactory
然后通过套件文件运行它。
您还可以在eclipse TestNG 插件 github 页面 https://github.com/cbeust/testng-eclipse并询问是否可以解决这个问题。
理想情况下讲@Factory
带注释的方法也可以被视为一个起点。虽然我不知道它的可行性。
我确实知道 IntelliJ 能够做到这一点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)