I\'ve got the following test:
@Test(expected = IllegalStateException.class)
public void testKey() {
int key = 1;
this.finder(key);
}
<
I had the same problem I just changed my imports statements. I removed :
import org.junit.jupiter.api.Test;
import junit.framework.TestCase;
and added :
import org.junit.Test;
And it worked fine for me.
I faced same issue, solution is simple "Don't extends TestCase class"
No, this JUnit test should work as it is - there is nothing more needed on this side.
What makes you sure that the test throws an IllegalStateException
? Is it possible that it gets wrapped into another exception of different type?
Please post the exact failure message from JUnit.
As @duffymo suggested, it is easy to verify what (if any) exception the test really throws.
@RunWith(JUnit4.class)
public class MyTestCaseBase extends TestCase
I also had problems with @Test(expected = ...) annotation when I extended TestCase class in my base test. Using @RunWith(JUnit4.class) helped instantly (not an extremely elegant solution, I admit)
Just tested this under JUnit4: this DO work, test completes successfully. Look if it is a Illegal
Selector
Exception
or such.
The problem was, that the class in which the test was nested was an extension of TestCase
. Since this is JUnit 3 style, the annotation didn't work.
Now my test class is a class on its own.