01: package test.methodselectors;
02:
03: import java.util.List;
04:
05: import org.testng.Assert;
06: import org.testng.ITestResult;
07: import org.testng.TestListenerAdapter;
08: import org.testng.TestNG;
09: import org.testng.annotations.Test;
10:
11: public class PriorityTest {
12:
13: private void runTest(int priority, String[] passedTests) {
14: TestNG tng = new TestNG();
15: tng.setVerbose(0);
16: tng.setTestClasses(new Class[] { PrioritySampleTest.class });
17: tng.addMethodSelector("test.methodselectors.NoTestSelector",
18: priority);
19: TestListenerAdapter tla = new TestListenerAdapter();
20: tng.addListener(tla);
21: tng.run();
22:
23: List<ITestResult> passed = tla.getPassedTests();
24: Assert.assertEquals(passedTests.length, passed.size());
25: if (passedTests.length == 1) {
26: String passed0 = passed.get(0).getName();
27: Assert.assertEquals(passed0, passedTests[0]);
28: }
29: if (passedTests.length == 2) {
30: String passed0 = passed.get(0).getName();
31: String passed1 = passed.get(1).getName();
32: Assert.assertTrue(passed0.equals(passedTests[0])
33: || passed0.equals(passedTests[1]));
34: Assert.assertTrue(passed1.equals(passedTests[0])
35: || passed1.equals(passedTests[1]));
36:
37: }
38: }
39:
40: // @Test
41: public void negativePriority() {
42: runTest(-5, new String[] {});
43: }
44:
45: @Test
46: public void lessThanTenPriority() {
47: runTest(5, new String[] { "alwaysRun" });
48: }
49:
50: // @Test
51: public void greaterThanTenPriority() {
52: runTest(15, new String[] { "alwaysRun", "neverRun" });
53: }
54:
55: }
|