【问题标题】:gradle test task failing on Test Util class extending TestCase but having no test methodgradle 测试任务在扩展 TestCase 但没有测试方法的 Test Util 类上失败
【发布时间】:2019-02-05 06:40:03
【问题描述】:

我有一个使用旧 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'   
}

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

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

【问题讨论】:

  • 只需添加一个测试方法。如果没有测试方法,该类无论如何都没有存在的理由

标签: java gradle junit


【解决方案1】:

来自 JUnit FAQ:

为什么我在运行测试时收到警告“AssertionFailedError: No tests found in XXX”?

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 2011-12-19
    相关资源
    最近更新 更多