gpt4 book ai didi

java - testNG 没有可运行的方法

转载 作者:行者123 更新时间:2023-11-30 04:15:26 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com