java - testNG 没有可运行的方法

标签 java junit testng

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

相关文章:

java - 与 Surefire Maven 插件并行运行 junit 测试

java - 如何从 JUnit 测试方法调用 Autowiring 服务

java - 如何通过程序跳过testNG.xml中提到的类

java - 什么是确定 2 个字符串是否为 "similar enough"的好指标

Java thenComparing通配符签名

Java 使用 JDBC 连接到 Cassandra [SQLNonTransientConnectionException : Keyspace names must be composed of alphanumerics and underscores]

java - JUnit、测试和线程

testing - TestNG中的环境配置

java - 以编程方式使用 TestNG 运行特定测试

java - Tomcat 中常用的 JNDI 资源