Last change
on this file since 830 was 501, checked in by wouter, 18 months ago |
added assertTrue to Assert (junit-t) and added test for it.
|
File size:
1.1 KB
|
Line | |
---|
1 | package testcode;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertTrue;
|
---|
5 |
|
---|
6 | public class AssertTest {
|
---|
7 |
|
---|
8 | public AssertTest() {
|
---|
9 | test1();
|
---|
10 | test2();
|
---|
11 | testAssertTrue();
|
---|
12 | }
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * The test code for Value
|
---|
16 | *
|
---|
17 | * @throws Exception
|
---|
18 | */
|
---|
19 | public static void main(String[] args) throws Exception {
|
---|
20 | new AssertTest();
|
---|
21 | }
|
---|
22 |
|
---|
23 | public static void test1() {
|
---|
24 | assertEquals(1, 1);
|
---|
25 | System.out.println("1ok");
|
---|
26 | }
|
---|
27 |
|
---|
28 | public static void test2() {
|
---|
29 | try {
|
---|
30 | assertEquals("not equal", 1, 2);
|
---|
31 | System.out.println("Test did not fail properly");
|
---|
32 | return;
|
---|
33 | } catch (AssertionError e) {
|
---|
34 | if (!e.getMessage().contains("not equal")) {
|
---|
35 | System.out.println(
|
---|
36 | "Test threw as expected but message does not contain 'not equal'");
|
---|
37 | return;
|
---|
38 | }
|
---|
39 | System.out.println("2ok");
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public static void testAssertTrue() {
|
---|
44 | try {
|
---|
45 | assertTrue("not true", false);
|
---|
46 | System.out.println("3ko");
|
---|
47 | } catch (AssertionError e) {
|
---|
48 | if (!e.getMessage().contains("not true"))
|
---|
49 | System.out.println("3missing message");
|
---|
50 | else
|
---|
51 | System.out.println("3ok");
|
---|
52 | }
|
---|
53 | }
|
---|
54 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.