- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我发现了一件奇怪的事情,我很想知道为什么会发生这种情况。我正在使用 Maven Surefire 插件 (2.12.4) 和 Junit 4.11。当我想使用 @Category 注释来禁用某些测试时。奇怪的是,它只有在不扩展 TestCase
的测试中才能正常工作。对于不扩展 TestCase 的测试,我只能将注释放在要运行/禁用的测试方法上,但对于其他方法,它会禁用类中的所有测试。例子:命令行:mvn test -Dgroups=!testgroups.DisabledTests
仅针对第一个代码段运行测试 B:
import static org.junit.Assert.*;
public class DataTest {
@Test
public void testA(){...}
@Test @Category(testgroups.DisabledTests.class)
public void testB(){...}
}
对于类扩展 TestCase
的第二种情况,它将不运行任何测试。
public class DataTest extends TestCase {
@Test
public void testA(){...}
@Test @Category(testgroups.DisabledTests.class)
public void testB(){...}
}
为什么会发生这种情况?
最佳答案
deborah-digges 的评论中给出了解决方案:
The problem is that the second class is an extension of TestCase. Since this is JUnit 3 style, the annotation @Category didn't work. Annotating the class with @RunWith(JUnit4.class) should give you the same result in both cases
另一个作者是 Stefan Birkner :
JUnit 4 finds test by looking for the
@Test
annotation. You can remove theextends TestCase
from your test class. Furthermore the name of the test method does no longer have to start withtest
. You're free to choose any method name you want.
关于java - JUnit 类别不适用于 TestCase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34635521/
我是一名优秀的程序员,十分优秀!