1 package test.thread; 2 3 import org.testng.annotations.AfterClass; 4 import org.testng.annotations.AfterMethod; 5 import org.testng.annotations.BeforeClass; 6 import org.testng.annotations.BeforeMethod; 7 import org.testng.annotations.Test; 8 import org.testng.collections.Lists; 9 10 import java.util.List; 11 12 public class MultiThreadedDependentSampleTest { 13 public static List<String> m_methods = Lists.newArrayList(); 14 15 @BeforeClass bc()16 public void bc() { 17 // log("beforeClass"); 18 } 19 20 @AfterClass ac()21 public void ac() { 22 // log("afterClass"); 23 } 24 25 @BeforeMethod bm()26 public void bm() { 27 // log("beforeMethod"); 28 } 29 30 @AfterMethod am()31 public void am() { 32 // log("afterMethod"); 33 } 34 35 @Test(groups = "1") a1()36 public void a1() { 37 logThread(); 38 log("a1"); 39 } 40 41 @Test(groups = "1") a2()42 public void a2() { 43 logThread(); 44 log("a2"); 45 } 46 47 @Test(groups = "1") a3()48 public void a3() { 49 logThread(); 50 log("a3"); 51 } 52 53 @Test(groups = "2", dependsOnGroups = "1") b1()54 public void b1() { 55 logThread(); 56 log("b1"); 57 } 58 59 @Test(groups = "2", dependsOnGroups = "1") b2()60 public void b2() { 61 logThread(); 62 log("b2"); 63 } 64 65 @Test(groups = "2", dependsOnGroups = "1") b3()66 public void b3() { 67 logThread(); 68 log("b3"); 69 } 70 71 @Test(groups = "2", dependsOnGroups = "1") b4()72 public void b4() { 73 logThread(); 74 log("b4"); 75 } 76 77 @Test(groups = "2", dependsOnGroups = "1") b5()78 public void b5() { 79 logThread(); 80 log("b5"); 81 } 82 83 @Test(dependsOnGroups = "2") c1()84 public void c1() { 85 logThread(); 86 log("c1"); 87 } 88 89 @Test(dependsOnGroups = { "1" }) d()90 public void d() { 91 logThread(); 92 log("d"); 93 } 94 95 @Test x()96 public void x() { 97 log("x"); 98 } 99 100 @Test y()101 public void y() { 102 log("y"); 103 } 104 105 @Test z()106 public void z() { 107 log("z"); 108 } 109 110 @Test t()111 public void t() { 112 log("t"); 113 } 114 115 // @Test(groups = "mytest", dependsOnMethods = "g") 116 // public void f() { 117 // } 118 // 119 // 120 // @AfterMethod 121 // public void after() { 122 // } 123 logThread()124 private void logThread() { 125 long id = Thread.currentThread().getId(); 126 Helper.getMap(getClass().getName()).put(id, id); 127 } 128 log(String string)129 private void log(String string) { 130 synchronized(m_methods) { 131 m_methods.add(string); 132 } 133 } 134 135 } 136