1 package test.dependent; 2 3 import org.testng.Assert; 4 import org.testng.TestNG; 5 import org.testng.annotations.Test; 6 import org.testng.collections.Lists; 7 8 import test.SimpleBaseTest; 9 10 import java.util.List; 11 12 public class GroupByInstancesTest extends SimpleBaseTest { 13 14 @Test dontGroupByInstances()15 public void dontGroupByInstances() { 16 runTest(false); 17 } 18 19 @Test groupByInstances()20 public void groupByInstances() { 21 runTest(true); 22 } 23 runTest(boolean group)24 private void runTest(boolean group) { 25 TestNG tng = create(GroupByInstancesSampleTest.class); 26 GroupByInstancesSampleTest.m_log = Lists.newArrayList(); 27 tng.setGroupByInstances(group); 28 tng.run(); 29 30 List<String> log = GroupByInstancesSampleTest.m_log; 31 int i = 0; 32 if (group) { 33 Assert.assertTrue(log.get(i++).startsWith("signIn")); 34 Assert.assertTrue(log.get(i++).startsWith("signOut")); 35 Assert.assertTrue(log.get(i++).startsWith("signIn")); 36 Assert.assertTrue(log.get(i++).startsWith("signOut")); 37 } else { 38 Assert.assertTrue(log.get(i++).startsWith("signIn")); 39 Assert.assertTrue(log.get(i++).startsWith("signIn")); 40 Assert.assertTrue(log.get(i++).startsWith("signOut")); 41 Assert.assertTrue(log.get(i++).startsWith("signOut")); 42 } 43 } 44 } 45