• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package test;
2 
3 import org.testng.Assert;
4 import org.testng.annotations.BeforeMethod;
5 import org.testng.annotations.Test;
6 
7 import test.junit.SetNameTest;
8 import test.sample.JUnitSample1;
9 import test.sample.JUnitSample2;
10 
11 
12 /**
13  * This class
14  *
15  * @author Cedric Beust, May 5, 2004
16  *
17  */
18 public class JUnitTest1 extends BaseTest {
19   @BeforeMethod(dependsOnGroups = { "initTest"} )
initJUnitFlag()20   public void initJUnitFlag() {
21     getTest().setJUnit(true);
22   }
23 
24   @Test
methodsThatStartWithTest()25   public void methodsThatStartWithTest() {
26     addClass("test.sample.JUnitSample1");
27     assert getTest().isJUnit();
28 
29     run();
30     String[] passed = {
31         JUnitSample1.EXPECTED1, JUnitSample1.EXPECTED2
32     };
33     String[] failed = {
34     };
35 
36     verifyTests("Passed", passed, getPassedTests());
37     verifyTests("Failed", failed, getFailedTests());
38   }
39 
40   @Test
methodsWithSetup()41   public void methodsWithSetup() {
42     addClass("test.sample.JUnitSample2");
43     run();
44     String[] passed = {
45       "testSample2ThatSetUpWasRun",
46     };
47     String[] failed = {
48     };
49 
50     verifyTests("Passed", passed, getPassedTests());
51     verifyTests("Failed", failed, getFailedTests());
52   }
53 
54   @Test
testSuite()55   public void testSuite() {
56     addClass("test.sample.AllJUnitTests");
57     run();
58     String[] passed = {
59         JUnitSample1.EXPECTED1, /*JUnitSample1.EXPECTED2,*/
60         JUnitSample2.EXPECTED,
61     };
62     String[] failed = {
63     };
64 
65     verifyTests("Passed", passed, getPassedTests());
66     verifyTests("Failed", failed, getFailedTests());
67   }
68 
69   @Test
testNewInstance()70   public void testNewInstance() {
71     addClass("test.sample.JUnitSample3");
72     run();
73     String[] passed = {
74       "test1", "test2"
75     };
76     String[] failed = {
77     };
78 
79     verifyTests("Passed", passed, getPassedTests());
80     verifyTests("Failed", failed, getFailedTests());
81   }
82 
83   @Test
setUpFailingShouldCauseMethodsToBeSkipped()84   public void setUpFailingShouldCauseMethodsToBeSkipped() {
85     addClass("test.junit.SetUpExceptionSampleTest");
86     run();
87     String[] passed = {
88     };
89     String[] failed = {
90       "testM1"/*, "testM1", "tearDown"*/
91     };
92     String[] skipped = {
93       /*"testM1", "tearDown"*/
94     };
95     verifyTests("Passed", passed, getPassedTests());
96     verifyTests("Skipped", skipped, getSkippedTests());
97     verifyTests("Failed", failed, getFailedTests());
98   }
99 
100   @Test
setNameShouldBeInvoked()101   public void setNameShouldBeInvoked() {
102     addClass("test.junit.SetNameTest");
103     SetNameTest.m_ctorCount = 0;
104     run();
105     String[] passed = {
106       "testFoo", "testBar",
107     };
108     String[] failed = {
109     };
110     String[] skipped = {
111     };
112     verifyTests("Passed", passed, getPassedTests());
113     verifyTests("Skipped", skipped, getSkippedTests());
114     verifyTests("Failed", failed, getFailedTests());
115 
116     Assert.assertEquals(SetNameTest.m_ctorCount, 2,
117         "Expected 2 instances to be created, found " + SetNameTest.m_ctorCount);
118   }
119 
ppp(String s)120   public static void ppp(String s) {
121     System.out.println("[JUnitTest1] " + s);
122   }
123 
124   @Test
testAbstract()125   public void testAbstract() {
126     addClass("test.sample.JUnitSample4");
127     run();
128     String[] passed = {
129       "testXY", "testXY", "testXY"
130     };
131     String[] failed = {
132     };
133 
134     verifyTests("Passed", passed, getPassedTests());
135     verifyTests("Failed", failed, getFailedTests());
136   }
137 }
138