我正在使用带有testng插件(版本6.14.0.201802161500)的eclipse 2018-09(4.9.0)。我创建了一个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>
1 回答
![?](http://img1.sycdn.imooc.com/5458478b0001f01502200220-100-100.jpg)
拉丁的传说
TA贡献1789条经验 获得超8个赞
之所以看到此行为,是因为TestNG eclipse插件会在@Test
通过右键单击启用该上下文选项之前,在一个类中查找任何测试方法(至少一个带有注释的方法)。
对于工厂(例如您的示例代码的SimpleTestFactory
外观),没有测试方法。这就是为什么它禁用该Run As > TestNG test
选项的原因。
因此,替代方法之一是基本上创建一个套件xml文件,添加一个引用SimpleTestFactory
,然后通过套件文件运行它。
您还可以在Eclipse TestNG插件github页面上提交问题,并询问是否可以解决。
理想情况下,带@Factory
注释的方法也可以视为起点。我不知道它的可行性。
我知道IntelliJ可以做到这一点。
添加回答
举报
0/150
提交
取消