I managed it to understand Junit 3.8 but honestly I have no idea how junit 4 works even after I read documentations for more than 45 minutes. I don't have a problem with the annotations but with running the tests. For example junit won't find my expected exception in this little example:
Output:
.E
Time: 0,011
There was 1 error:
1) testTest(junittests.TestTestCase)java.util.InputMismatchException
Main.java
TestRunner.run(TestTestCase.class);
DemoClass.java
import java.util.InputMismatchException;
public class DemoClass {
public void test() {
throw new InputMismatchException();
}
}
TestTestCase.java
import junit.framework.TestCase;
import org.junit.Before;
import java.util.InputMismatchException;
public class TestTestCase extends TestCase {
private DemoClass inst;
@Before
public void setUp() {
inst = new DemoClass();
}
@org.junit.Test(expected = InputMismatchException.class)
public void testTest() {
inst.test();
}
}
I really have no clue how to use it. Thanks a lot in advance!