01: package test.factory;
02:
03: import static org.testng.Assert.assertEquals;
04:
05: import java.util.ArrayList;
06: import java.util.List;
07:
08: import org.testng.annotations.AfterMethod;
09: import org.testng.annotations.AfterSuite;
10: import org.testng.annotations.BeforeMethod;
11: import org.testng.annotations.BeforeSuite;
12: import org.testng.annotations.Test;
13:
14: /**
15: * Test that setUp methods are correctly interleaved even
16: * when we use similar instances of a same test class.
17: *
18: * @author cbeust
19: */
20: public class Sample2 {
21: private static List<String> m_methodList = new ArrayList<String>();
22:
23: @BeforeSuite
24: public void init() {
25: m_methodList = new ArrayList<String>();
26: }
27:
28: @BeforeMethod
29: public void setUp() {
30: ppp("SET UP");
31: m_methodList.add("setUp");
32: }
33:
34: @AfterMethod
35: public void tearDown() {
36: ppp("TEAR DOWN");
37: m_methodList.add("tearDown");
38: }
39:
40: @AfterSuite
41: public void afterSuite() {
42: String[] expectedStrings = { "setUp", "testInputImages",
43: "tearDown", "setUp", "testInputImages", "tearDown",
44: "setUp", "testImages", "tearDown", "setUp",
45: "testImages", "tearDown", };
46: List<String> expected = new ArrayList<String>();
47: for (String s : expectedStrings) {
48: expected.add(s);
49: }
50:
51: ppp("ORDER OF METHODS:");
52: for (String s : m_methodList) {
53: ppp(" " + s);
54: }
55:
56: assertEquals(m_methodList, expected);
57: }
58:
59: @Test
60: public void testInputImages() {
61: m_methodList.add("testInputImages");
62: ppp("TESTINPUTIMAGES");
63: }
64:
65: @Test(dependsOnMethods={"testInputImages"})
66: public void testImages() {
67: m_methodList.add("testImages");
68: }
69:
70: private static void ppp(String s) {
71: if (false) {
72: System.out.println("[Sample2] " + s);
73: }
74: }
75: }
|