01: package test.conffailure;
02:
03: import org.testng.TestListenerAdapter;
04: import org.testng.TestNG;
05: import org.testng.annotations.Test;
06:
07: import testhelper.OutputDirectoryPatch;
08:
09: import static org.testng.Assert.assertTrue;
10:
11: /**
12: * Test various cases where the @Configuration methods fail
13: *
14: * Created on Jul 20, 2005
15: * @author cbeust
16: */
17: public class ConfigurationFailure {
18:
19: @Test
20: public void beforeTestClassFails() {
21: TestListenerAdapter tla = new TestListenerAdapter();
22: TestNG testng = new TestNG();
23: testng.setOutputDirectory(OutputDirectoryPatch
24: .getOutputDirectory());
25: testng.setTestClasses(new Class[] {
26: ClassWithFailedBeforeTestClass.class,
27: ClassWithFailedBeforeTestClassVerification.class });
28: testng.addListener(tla);
29: testng.setVerbose(0);
30: testng.run();
31: assertTrue(
32: ClassWithFailedBeforeTestClassVerification.success(),
33: "Not all the @Configuration methods of Run2 were run");
34: }
35:
36: @Test
37: public void beforeTestSuiteFails() {
38: TestListenerAdapter tla = new TestListenerAdapter();
39: TestNG testng = new TestNG();
40: testng.setOutputDirectory(OutputDirectoryPatch
41: .getOutputDirectory());
42: testng.setTestClasses(new Class[] {
43: ClassWithFailedBeforeSuite.class,
44: ClassWithFailedBeforeSuiteVerification.class });
45: testng.addListener(tla);
46: testng.setVerbose(0);
47: testng.run();
48: assertTrue(ClassWithFailedBeforeSuiteVerification.success(),
49: "No @Configuration methods should have run");
50: }
51:
52: private static void ppp(String s) {
53: System.out.println("[AlwaysRunTest] " + s);
54: }
55: }
|