package testcode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import org.junit.Ignore; import org.junit.Test; import org.junit.internal.runners.JUnit4ClassRunner; import org.junit.runner.RunWith; /** * Test that having a @Test annotation results in the translated class to extend * unittest.TestCase. We can not test this in java, therefore this class is not * runnable. */ @RunWith(JUnit4ClassRunner.class) public class SomeUnitTest { public SomeUnitTest() { // do nothing. This is just to test that // we can handle the presence of a constructor. } /** * NOTE NO CONSTRUCTOR. This is needed to check that the proper constructor, * matching in this case the implicit superclass TestCase from Python, is * created. This is a special case, in normal cases java already enforces * all required code including the call to super(). */ @Test public void test1() { assertFalse(1 == value()); } private int value() { return 2; } /** * This test does not have the name testXXX.java and therefore the * translator must introduce a new method that does start with "test" */ @Test public void someTest() { assertEquals(2, value()); } /** * Translating this must result in testRaises(). This test must NOT start * with 'test' */ @Test(expected = ArithmeticException.class) public void NullTest() { int x = 1 / 0; } @Test @Ignore public void failingTest1() { throw new IllegalStateException("This test always fails"); } @Ignore @Test public void failingTest21() { throw new IllegalStateException("This test always fails"); } }