Skip to content

Instantly share code, notes, and snippets.

@krmahadevan
Created February 16, 2017 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krmahadevan/65847122ba41ee485f72ab4e920d4436 to your computer and use it in GitHub Desktop.
Save krmahadevan/65847122ba41ee485f72ab4e920d4436 to your computer and use it in GitHub Desktop.
package com.rationaleemotions.stackoverflow;
import org.testng.annotations.Test;
public class ChildClassOne extends MyBaseClass {
public ChildClassOne() {
super(false);
}
@Test
public void testMethod() {
System.err.println("Test Method from " + getClass().getName());
}
}
package com.rationaleemotions.stackoverflow;
import org.testng.annotations.Test;
public class ChildClassTwo extends MyBaseClass {
public ChildClassTwo() {
super(true);
}
@Test
public void testMethod() {
System.err.println("Test Method from " + getClass().getName());
}
}
package com.rationaleemotions.stackoverflow;
import org.testng.annotations.BeforeClass;
public class MyBaseClass {
protected boolean shouldFail = false;
public MyBaseClass(boolean shouldFail) {
this.shouldFail = shouldFail;
}
@BeforeClass
public void beforeClass() {
if (shouldFail) {
throw new IllegalStateException("Un-defined state");
}
System.err.println("BeforeClass invoked from " + getClass().getName());
}
}
package com.rationaleemotions.stackoverflow;
import org.testng.TestNG;
import org.testng.xml.XmlSuite;
public class TestRunner {
public static void main(String[] args) {
TestNG tng = new TestNG();
tng.setVerbose(2);
tng.setUseDefaultListeners(true);
tng.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE);
tng.setTestClasses(new Class[] {ChildClassOne.class, ChildClassTwo.class});
tng.run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment