JUnit期望标记无法按预期工作 [英] JUnit expected tag not working as expected
问题描述
我在eclipse中有以下测试用例,使用拒绝传递的JUnit 4。 可能出现什么问题?
I have the following test case in eclipse, using JUnit 4 which is refusing to pass. What could be wrong?
@Test(expected = IllegalArgumentException.class)
public void testIAE() {
throw new IllegalArgumentException();
}
当尝试使用期望的标签测试我自己的代码时出现了这个确切的测试用例没用。我想知道JUnit是否会通过最基本的测试。它没有。
This exact testcase came about when trying to test my own code with the expected tag didn't work. I wanted to see if JUnit would pass the most basic test. It didn't.
我还测试了自定义异常,没有运气。
I've also tested with custom exceptions as expected without luck.
截图:
截图http://www.freeimagehosting.net/uploads/6a995b0db7.png
推荐答案
问题是你的AnnounceThreadTest扩展了TestCase。因为它扩展了TestCase,所以JUnit Runner将它视为JUnit 3.8测试,并且测试正在运行,因为它以单词test开头,隐藏了@Test注释实际上根本没有被使用的事实。
The problem is that your AnnounceThreadTest extends TestCase. Because it extends TestCase, the JUnit Runner is treating it as a JUnit 3.8 test, and the test is running because it starts with the word test, hiding the fact that the @Test annotiation is in fact not being used at all.
要解决此问题,请从类定义中删除extends TestCase。
To fix this, remove the "extends TestCase" from the class definition.
这篇关于JUnit期望标记无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!