我正在使用 TestNG 编写集成测试并面临这个小问题。
No runnable methods
java.lang.Exception: No runnable methods
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
测试类是这样的(根据Stephen的建议,我删除了SpringJunitRunner):
@Test
@ContextConfiguration(locations = { "file:spring-configuration/mobiusdatabase-integration-testing.xml" })
public class PersistUrlTests extends AbstractTestNGSpringContextTests {
@Autowired
protected MobiusDatabaseServiceClient mobiusDatabaseServiceClient;
@Autowired
UrlDAO urlDAO;
@Autowired
ScraperUrlDAO scraperUrlDAO;
@BeforeClass
public static void init() throws Exception {
}
@Test
public void checkTest() {
GetActiveCategoriesResponse response = mobiusDatabaseServiceClient.newGetActiveCategoriesCall().call();
System.out.println(response.getCategoryList());
Assert.assertTrue(true);
}
}
当我们没有@Test
注释或者没有@Runner
时,通常会发生此错误。我们需要为 TestNG
进行一些其他设置吗?
最佳答案
您正在尝试使用 SpringJUnit4ClassRunner
运行 TestNG 单元测试。那是行不通的。 JUnit
运行程序期望找到由不同 @Test
注释指定的测试类。
我不知道正确的解决方案是什么,因为明显的包中没有 SpringTestNGClassRunner
类。
更新 - 这是解释!
关于java - testNG 没有可运行的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18527267/