01: package test.alwaysrun;
02:
03: import org.testng.Assert;
04: import org.testng.TestNG;
05:
06: import testhelper.OutputDirectoryPatch;
07:
08: public class AlwaysRunTest {
09: static StringBuffer LOG;
10:
11: /**
12: * @testng.test
13: */
14: public void checkAlwaysRunTestMethod() {
15: LOG = new StringBuffer();
16: TestNG runner = new TestNG();
17: runner.setOutputDirectory(OutputDirectoryPatch
18: .getOutputDirectory());
19: runner.setVerbose(1);
20: runner
21: .setTestClasses(new Class[] { ClassWithAlwaysAfterTestMethod.class });
22: runner.run();
23:
24: Assert.assertEquals(LOG.toString(),
25: "-before-nonfail-after-before-fail-after",
26: "all methods should have been invoked");
27: }
28:
29: /**
30: * @testng.test
31: */
32: public void checkAlwaysRunClassMethod() {
33: LOG = new StringBuffer();
34: TestNG runner = new TestNG();
35: runner.setOutputDirectory(OutputDirectoryPatch
36: .getOutputDirectory());
37: runner.setVerbose(1);
38: runner
39: .setTestClasses(new Class[] { ClassWithAlwaysAfterClassMethod.class });
40: runner.run();
41:
42: Assert.assertEquals(LOG.toString(),
43: "-before-nonfail-fail-after",
44: "all methods should have been invoked");
45: }
46:
47: /**
48: * @testng.test
49: */
50: public void checkWithInnerClass() {
51: LOG = new StringBuffer();
52: TestNG runner = new TestNG();
53: runner.setOutputDirectory(OutputDirectoryPatch
54: .getOutputDirectory());
55: runner.setVerbose(1);
56: runner.setTestClasses(new Class[] { SimpleInnerClass.class });
57: runner.run();
58:
59: Assert.assertEquals(LOG.toString(), "dummy",
60: "inner class should have been run");
61: }
62:
63: static class SimpleInnerClass {
64: /**
65: * @testng.test
66: */
67: public void dummyTest() {
68: LOG.append("dummy");
69: }
70: }
71: }
|