-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow listeners to be disabled at runtime
Closes #2381
- Loading branch information
1 parent
23bb95f
commit 93ec005
Showing
10 changed files
with
324 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
testng-core/src/test/java/test/listeners/issue2381/FactoryTestClassSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package test.listeners.issue2381; | ||
|
||
import org.testng.annotations.AfterSuite; | ||
import org.testng.annotations.BeforeSuite; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
public class FactoryTestClassSample { | ||
|
||
@Factory(dataProvider = "dp") | ||
public FactoryTestClassSample(int ignored) {} | ||
|
||
@DataProvider | ||
public static Object[][] dp() { | ||
return new Object[][] {{1}}; | ||
} | ||
|
||
@BeforeSuite | ||
public void beforeSuite() {} | ||
|
||
@Test | ||
public void testMethod() {} | ||
|
||
@AfterSuite | ||
public void afterSuite() {} | ||
} |
141 changes: 141 additions & 0 deletions
141
testng-core/src/test/java/test/listeners/issue2381/SampleGlobalListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package test.listeners.issue2381; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.testng.IAlterSuiteListener; | ||
import org.testng.IClassListener; | ||
import org.testng.IExecutionListener; | ||
import org.testng.IExecutionVisualiser; | ||
import org.testng.IInvokedMethod; | ||
import org.testng.IInvokedMethodListener; | ||
import org.testng.IReporter; | ||
import org.testng.ISuite; | ||
import org.testng.ISuiteListener; | ||
import org.testng.ITestClass; | ||
import org.testng.ITestContext; | ||
import org.testng.ITestListener; | ||
import org.testng.ITestResult; | ||
import org.testng.xml.XmlSuite; | ||
|
||
public class SampleGlobalListener | ||
implements IExecutionListener, | ||
IAlterSuiteListener, | ||
ISuiteListener, | ||
ITestListener, | ||
IInvokedMethodListener, | ||
IClassListener, | ||
IExecutionVisualiser, | ||
IReporter { | ||
|
||
private static final List<String> logs = new ArrayList<>(); | ||
|
||
public static List<String> getLogs() { | ||
return Collections.unmodifiableList(logs); | ||
} | ||
|
||
public static void clearLogs() { | ||
logs.clear(); | ||
} | ||
|
||
@Override | ||
public void onExecutionStart() { | ||
logs.add("onExecutionStart"); | ||
} | ||
|
||
@Override | ||
public void alter(List<XmlSuite> suites) { | ||
logs.add("alter"); | ||
} | ||
|
||
@Override | ||
public void onStart(ISuite suite) { | ||
logs.add("onStart(ISuite)"); | ||
} | ||
|
||
@Override | ||
public void onStart(ITestContext context) { | ||
logs.add("onStart(ITestContext)"); | ||
} | ||
|
||
@Override | ||
public void onBeforeClass(ITestClass testClass) { | ||
logs.add("onBeforeClass"); | ||
} | ||
|
||
@Override | ||
public void consumeDotDefinition(String dotDefinition) { | ||
logs.add("consumeDotDefinition"); | ||
} | ||
|
||
@Override | ||
public void onTestStart(ITestResult result) { | ||
logs.add("onTestStart(ITestResult)"); | ||
} | ||
|
||
@Override | ||
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { | ||
logs.add("beforeInvocation"); | ||
} | ||
|
||
@Override | ||
public void afterInvocation(IInvokedMethod method, ITestResult testResult) { | ||
logs.add("afterInvocation"); | ||
} | ||
|
||
@Override | ||
public void onTestSuccess(ITestResult result) { | ||
logs.add("onTestSuccess(ITestResult)"); | ||
} | ||
|
||
@Override | ||
public void onTestFailure(ITestResult result) { | ||
logs.add("onTestFailure(ITestResult)"); | ||
} | ||
|
||
@Override | ||
public void onTestSkipped(ITestResult result) { | ||
logs.add("onTestSkipped(ITestResult)"); | ||
} | ||
|
||
@Override | ||
public void onTestFailedButWithinSuccessPercentage(ITestResult result) { | ||
logs.add("onTestFailedButWithinSuccessPercentage(ITestResult)"); | ||
} | ||
|
||
@Override | ||
public void onTestFailedWithTimeout(ITestResult result) { | ||
logs.add("onTestFailedWithTimeout(ITestResult)"); | ||
} | ||
|
||
@Override | ||
public void onAfterClass(ITestClass testClass) { | ||
logs.add("onAfterClass"); | ||
} | ||
|
||
@Override | ||
public void onFinish(ITestContext context) { | ||
logs.add("onFinish(ITestContext)"); | ||
} | ||
|
||
@Override | ||
public void onFinish(ISuite suite) { | ||
logs.add("onFinish(ISuite)"); | ||
} | ||
|
||
@Override | ||
public void generateReport( | ||
List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) { | ||
logs.add("generateReport"); | ||
} | ||
|
||
@Override | ||
public void onExecutionFinish() { | ||
logs.add("onExecutionFinish"); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return false; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
testng-core/src/test/java/test/listeners/issue2381/SampleTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package test.listeners.issue2381; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.testng.IAnnotationTransformer; | ||
import org.testng.annotations.IConfigurationAnnotation; | ||
import org.testng.annotations.IDataProviderAnnotation; | ||
import org.testng.annotations.IFactoryAnnotation; | ||
import org.testng.annotations.IListenersAnnotation; | ||
import org.testng.annotations.ITestAnnotation; | ||
|
||
public class SampleTransformer implements IAnnotationTransformer { | ||
|
||
private static final List<String> logs = new ArrayList<>(); | ||
|
||
public static List<String> getLogs() { | ||
return Collections.unmodifiableList(logs); | ||
} | ||
|
||
public static void clearLogs() { | ||
logs.clear(); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void transform(IListenersAnnotation annotation, Class<?> testClass) { | ||
logs.add("transform_listener"); | ||
} | ||
|
||
@Override | ||
public void transform(IDataProviderAnnotation annotation, Method method) { | ||
logs.add("transform_data_provider"); | ||
} | ||
|
||
@Override | ||
public void transform(IFactoryAnnotation annotation, Method method) { | ||
logs.add("transform_factory"); | ||
} | ||
|
||
@Override | ||
public void transform( | ||
IConfigurationAnnotation annotation, | ||
Class testClass, | ||
Constructor testConstructor, | ||
Method testMethod) { | ||
logs.add("transform_configuration"); | ||
} | ||
|
||
@Override | ||
public void transform( | ||
ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { | ||
logs.add("transform_test"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
testng-core/src/test/java/test/listeners/issue2381/TestClassSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package test.listeners.issue2381; | ||
|
||
import org.testng.IExecutionListener; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners(TestClassSample.MyListener.class) | ||
public class TestClassSample { | ||
|
||
@BeforeClass | ||
public void beforeClass() {} | ||
|
||
@Test | ||
public void testMethod() {} | ||
|
||
public static class MyListener implements IExecutionListener {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> | ||
<suite name="2381_suite" verbose="2"> | ||
<listeners> | ||
<listener class-name="test.listeners.issue2381.SampleTransformer"/> | ||
<listener class-name="test.listeners.issue2381.SampleGlobalListener"/> | ||
</listeners> | ||
|
||
<test name="2381_test" verbose="2"> | ||
<classes> | ||
<class name="test.listeners.issue2381.TestClassSample"/> | ||
<class name="test.listeners.issue2381.FactoryTestClassSample"/> | ||
</classes> | ||
</test> | ||
|
||
</suite> | ||
|