Last change
on this file since 1304 was 958, checked in by wouter, 5 months ago |
#325 changed translation of standard unit tests. They now also the original, unchanged class plus some extra class that calls the tests. This ensures it also works if the test class has a constructor.
|
File size:
1.4 KB
|
Line | |
---|
1 | package testcode;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 |
|
---|
6 | import org.junit.Test;
|
---|
7 | import org.junit.internal.runners.JUnit4ClassRunner;
|
---|
8 | import org.junit.runner.RunWith;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Test that having a @Test annotation results in the translated class to extend
|
---|
12 | * unittest.TestCase. We can not test this in java, therefore this class is not
|
---|
13 | * runnable.
|
---|
14 | */
|
---|
15 | @RunWith(JUnit4ClassRunner.class)
|
---|
16 | public class SomeUnitTest {
|
---|
17 |
|
---|
18 | public SomeUnitTest() {
|
---|
19 | // do nothing. This is just to test that
|
---|
20 | // we can handle the presence of a constructor.
|
---|
21 | }
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * NOTE NO CONSTRUCTOR. This is needed to check that the proper constructor,
|
---|
25 | * matching in this case the implicit superclass TestCase from Python, is
|
---|
26 | * created. This is a special case, in normal cases java already enforces
|
---|
27 | * all required code including the call to super().
|
---|
28 | */
|
---|
29 | @Test
|
---|
30 | public void test1() {
|
---|
31 | assertFalse(1 == value());
|
---|
32 | }
|
---|
33 |
|
---|
34 | private int value() {
|
---|
35 | return 2;
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * This test does not have the name testXXX.java and therefore the
|
---|
40 | * translator must introduce a new method that does start with "test"
|
---|
41 | */
|
---|
42 | @Test
|
---|
43 | public void someTest() {
|
---|
44 | assertEquals(2, value());
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Translating this must result in testRaises(). This test must NOT start
|
---|
49 | * with 'test'
|
---|
50 | */
|
---|
51 | @Test(expected = ArithmeticException.class)
|
---|
52 | public void NullTest() {
|
---|
53 | int x = 1 / 0;
|
---|
54 | }
|
---|
55 |
|
---|
56 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.