01: package test;
02:
03: import java.util.List;
04:
05: import org.testng.ITestResult;
06: import org.testng.TestListenerAdapter;
07: import org.testng.TestNG;
08:
09: import test.sample.JUnitSample1;
10:
11: import testhelper.OutputDirectoryPatch;
12:
13: public class CommandLineTest {
14:
15: /**
16: * Test -junit
17: *
18: * @testng.test groups = "current"
19: */
20: public void junitParsing() {
21: String[] argv = { "-sourcedir", "src", "-d",
22: OutputDirectoryPatch.getOutputDirectory(), "-log", "0",
23: "-junit", "-testclass", "test.sample.JUnitSample1" };
24: TestListenerAdapter tla = new TestListenerAdapter();
25: TestNG.privateMain(argv, tla);
26:
27: List passed = tla.getPassedTests();
28: assert passed.size() == 2;
29: String test1 = ((ITestResult) passed.get(0)).getName();
30: String test2 = ((ITestResult) passed.get(1)).getName();
31:
32: assert JUnitSample1.EXPECTED1.equals(test1)
33: && JUnitSample1.EXPECTED2.equals(test2)
34: || JUnitSample1.EXPECTED1.equals(test2)
35: && JUnitSample1.EXPECTED2.equals(test1);
36: }
37:
38: /**
39: * Test the absence of -junit
40: *
41: * @testng.test groups = "current"
42: */
43: public void junitParsing2() {
44: String[] argv = { "-sourcedir", "src", "-log", "0", "-d",
45: OutputDirectoryPatch.getOutputDirectory(),
46: "-testclass", "test.sample.JUnitSample1" };
47: TestListenerAdapter tla = new TestListenerAdapter();
48: TestNG.privateMain(argv, tla);
49:
50: List passed = tla.getPassedTests();
51: assert passed.size() == 0;
52: }
53:
54: private static void ppp(String s) {
55: System.out.println("[CommandLineTest] " + s);
56: }
57:
58: }
|