1 | package testcode;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 |
|
---|
6 | import org.junit.Ignore;
|
---|
7 | import org.junit.Test;
|
---|
8 | import org.junit.internal.runners.JUnit4ClassRunner;
|
---|
9 | import org.junit.runner.RunWith;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Test that having a @Test annotation results in the translated class to extend
|
---|
13 | * unittest.TestCase. We can not test this in java, therefore this class is not
|
---|
14 | * runnable.
|
---|
15 | */
|
---|
16 | @RunWith(JUnit4ClassRunner.class)
|
---|
17 | public class SomeUnitTest {
|
---|
18 |
|
---|
19 | public SomeUnitTest() {
|
---|
20 | // do nothing. This is just to test that
|
---|
21 | // we can handle the presence of a constructor.
|
---|
22 | }
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * NOTE NO CONSTRUCTOR. This is needed to check that the proper constructor,
|
---|
26 | * matching in this case the implicit superclass TestCase from Python, is
|
---|
27 | * created. This is a special case, in normal cases java already enforces
|
---|
28 | * all required code including the call to super().
|
---|
29 | */
|
---|
30 | @Test
|
---|
31 | public void test1() {
|
---|
32 | assertFalse(1 == value());
|
---|
33 | }
|
---|
34 |
|
---|
35 | private int value() {
|
---|
36 | return 2;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * This test does not have the name testXXX.java and therefore the
|
---|
41 | * translator must introduce a new method that does start with "test"
|
---|
42 | */
|
---|
43 | @Test
|
---|
44 | public void someTest() {
|
---|
45 | assertEquals(2, value());
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Translating this must result in testRaises(). This test must NOT start
|
---|
50 | * with 'test'
|
---|
51 | */
|
---|
52 | @Test(expected = ArithmeticException.class)
|
---|
53 | public void NullTest() {
|
---|
54 | int x = 1 / 0;
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Test
|
---|
58 | @Ignore
|
---|
59 | public void failingTest1() {
|
---|
60 | throw new IllegalStateException("This test always fails");
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Ignore
|
---|
64 | @Test
|
---|
65 | public void failingTest21() {
|
---|
66 | throw new IllegalStateException("This test always fails");
|
---|
67 | }
|
---|
68 |
|
---|
69 | }
|
---|