gradle 测试任务在扩展测试用例的测试实用程序类上失败,但没有测试方法



我有一个使用旧 Junit 3 方式的旧版测试类:

public class MyTestUtil extends TestCase {
  //class has helper methods but no method starting with "test"
}

我还有其他扩展此类的测试类:

public class MyTests extends MyTestUtil {
       public void testSomething() {
       }
}

我正在尝试使用 gradle 构建文件运行它。并且构建失败并发出警告:

junit.framework.AssertionFailedError: No tests found in myPackage.MyTestUtil

当我从测试任务中排除此类时,构建显然运行良好:

test {
  exclude '**/MyTestUtil.class'   
}

但我不知道像这样排除是否是唯一的解决方案。

有没有办法消除这个警告?

来自 JUnit FAQ

为什么我在运行测试时收到警告"断言失败错误:在 XXX 中找不到测试"?

确保您有更多或更多方法用 @Test 注释。

要么添加至少一个测试,要么像你描述的那样排除该类。

相关内容

最新更新