Last change
on this file since 896 was 896, checked in by wouter, 5 months ago |
#310 moved GetResourcesTest to junit-t because this test is so much easier if we have junit translator and package translation. junit tests now require @RunWith annotation for proper translation. Added more translators
|
File size:
1.2 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 |
|
---|
[730] | 18 | /**
|
---|
| 19 | * NOTE NO CONSTRUCTOR. This is needed to check that the proper constructor,
|
---|
| 20 | * matching in this case the implicit superclass TestCase from Python, is
|
---|
| 21 | * created. This is a special case, in normal cases java already enforces
|
---|
| 22 | * all required code including the call to super().
|
---|
| 23 | */
|
---|
[717] | 24 | @Test
|
---|
| 25 | public void test1() {
|
---|
[730] | 26 | assertFalse(1 == value());
|
---|
[717] | 27 | }
|
---|
| 28 |
|
---|
[730] | 29 | private int value() {
|
---|
| 30 | return 2;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[721] | 33 | /**
|
---|
| 34 | * This test does not have the name testXXX.java and therefore the
|
---|
| 35 | * translator must introduce a new method that does start with "test"
|
---|
| 36 | */
|
---|
| 37 | @Test
|
---|
[896] | 38 | public void someTest() {
|
---|
[730] | 39 | assertEquals(2, value());
|
---|
[721] | 40 | }
|
---|
| 41 |
|
---|
| 42 | /**
|
---|
[896] | 43 | * Translating this must result in testRaises(). This test must NOT start
|
---|
| 44 | * with 'test'
|
---|
[721] | 45 | */
|
---|
[730] | 46 | @Test(expected = ArithmeticException.class)
|
---|
[896] | 47 | public void NullTest() {
|
---|
[730] | 48 | int x = 1 / 0;
|
---|
[721] | 49 | }
|
---|
| 50 |
|
---|
[717] | 51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.