Last change
on this file since 1030 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
|
Rev | Line | |
---|
[717] | 1 | package testcode;
|
---|
| 2 |
|
---|
[730] | 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 | import static org.junit.Assert.assertFalse;
|
---|
| 5 |
|
---|
[717] | 6 | import org.junit.Test;
|
---|
[896] | 7 | import org.junit.internal.runners.JUnit4ClassRunner;
|
---|
| 8 | import org.junit.runner.RunWith;
|
---|
[717] | 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 | */
|
---|
[896] | 15 | @RunWith(JUnit4ClassRunner.class)
|
---|
[717] | 16 | public class SomeUnitTest {
|
---|
| 17 |
|
---|
[958] | 18 | public SomeUnitTest() {
|
---|
| 19 | // do nothing. This is just to test that
|
---|
| 20 | // we can handle the presence of a constructor.
|
---|
| 21 | }
|
---|
| 22 |
|
---|
[730] | 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 | */
|
---|
[717] | 29 | @Test
|
---|
| 30 | public void test1() {
|
---|
[730] | 31 | assertFalse(1 == value());
|
---|
[717] | 32 | }
|
---|
| 33 |
|
---|
[730] | 34 | private int value() {
|
---|
| 35 | return 2;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[721] | 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
|
---|
[896] | 43 | public void someTest() {
|
---|
[730] | 44 | assertEquals(2, value());
|
---|
[721] | 45 | }
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
[896] | 48 | * Translating this must result in testRaises(). This test must NOT start
|
---|
| 49 | * with 'test'
|
---|
[721] | 50 | */
|
---|
[730] | 51 | @Test(expected = ArithmeticException.class)
|
---|
[896] | 52 | public void NullTest() {
|
---|
[730] | 53 | int x = 1 / 0;
|
---|
[721] | 54 | }
|
---|
| 55 |
|
---|
[717] | 56 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.