-
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.
Streamline TestResult management from listeners
Fixes #1632
- Loading branch information
1 parent
50c08c0
commit 636a825
Showing
9 changed files
with
192 additions
and
3 deletions.
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
31 changes: 31 additions & 0 deletions
31
src/test/java/test/skip/github1632/ListenerMarksMethodAsSkippedSample.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,31 @@ | ||
package test.skip.github1632; | ||
|
||
|
||
import org.testng.IInvokedMethod; | ||
import org.testng.IInvokedMethodListener; | ||
import org.testng.ITestResult; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners(ListenerMarksMethodAsSkippedSample.MySkipTestListener.class) | ||
public class ListenerMarksMethodAsSkippedSample { | ||
|
||
@BeforeMethod | ||
void beforeMethod() { | ||
} | ||
|
||
@Test | ||
void shouldNotBeExecuted() { | ||
} | ||
|
||
public static class MySkipTestListener implements IInvokedMethodListener { | ||
|
||
@Override | ||
public void afterInvocation(IInvokedMethod method, ITestResult testResult) { | ||
testResult.setStatus(ITestResult.SKIP); | ||
} | ||
} | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package test_result; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.testng.IInvokedMethod; | ||
import org.testng.IInvokedMethodListener; | ||
import org.testng.ITestContext; | ||
import org.testng.ITestListener; | ||
import org.testng.ITestNGListener; | ||
import org.testng.ITestResult; | ||
|
||
public class OrderAbidingListener implements IInvokedMethodListener, ITestListener { | ||
|
||
private final List<ITestNGListener> listeners; | ||
|
||
public OrderAbidingListener(ITestNGListener ...listeners) { | ||
this.listeners = Arrays.asList(listeners); | ||
} | ||
|
||
@Override | ||
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { | ||
listeners.stream() | ||
.filter(l-> l instanceof IInvokedMethodListener) | ||
.map( l -> (IInvokedMethodListener) l ) | ||
.forEach(l-> l.beforeInvocation(method, testResult)); | ||
} | ||
|
||
@Override | ||
public void beforeInvocation(IInvokedMethod method, ITestResult testResult, | ||
ITestContext context) { | ||
listeners.stream() | ||
.filter(l-> l instanceof IInvokedMethodListener) | ||
.map( l -> (IInvokedMethodListener) l ) | ||
.forEach(l-> l.beforeInvocation(method, testResult, context)); | ||
|
||
} | ||
|
||
@Override | ||
public void afterInvocation(IInvokedMethod method, ITestResult testResult) { | ||
listeners.stream() | ||
.filter(l-> l instanceof IInvokedMethodListener) | ||
.map( l -> (IInvokedMethodListener) l ) | ||
.forEach(l-> l.afterInvocation(method, testResult)); | ||
} | ||
|
||
@Override | ||
public void afterInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) { | ||
listeners.stream() | ||
.filter(l-> l instanceof IInvokedMethodListener) | ||
.map( l -> (IInvokedMethodListener) l ) | ||
.forEach(l-> l.afterInvocation(method, testResult, context)); | ||
} | ||
|
||
@Override | ||
public void onStart(ITestContext context) { | ||
listeners.stream() | ||
.filter(l-> l instanceof ITestListener) | ||
.map( l -> (ITestListener) l ) | ||
.forEach(l-> l.onStart(context)); | ||
} | ||
|
||
@Override | ||
public void onTestStart(ITestResult result) { | ||
listeners.stream() | ||
.filter(l-> l instanceof ITestListener) | ||
.map( l -> (ITestListener) l ) | ||
.forEach(l-> l.onTestStart(result)); | ||
} | ||
|
||
@Override | ||
public void onTestSuccess(ITestResult result) { | ||
listeners.stream() | ||
.filter(l-> l instanceof ITestListener) | ||
.map( l -> (ITestListener) l ) | ||
.forEach(l-> l.onTestSuccess(result)); | ||
} | ||
|
||
@Override | ||
public void onTestFailure(ITestResult result) { | ||
listeners.stream() | ||
.filter(l-> l instanceof ITestListener) | ||
.map( l -> (ITestListener) l ) | ||
.forEach(l-> l.onTestFailure(result)); | ||
} | ||
|
||
@Override | ||
public void onTestSkipped(ITestResult result) { | ||
listeners.stream() | ||
.filter(l-> l instanceof ITestListener) | ||
.map( l -> (ITestListener) l ) | ||
.forEach(l-> l.onTestSkipped(result)); | ||
} | ||
|
||
@Override | ||
public void onTestFailedButWithinSuccessPercentage(ITestResult result) { | ||
listeners.stream() | ||
.filter(l-> l instanceof ITestListener) | ||
.map( l -> (ITestListener) l ) | ||
.forEach(l-> l.onTestFailedButWithinSuccessPercentage(result)); | ||
} | ||
|
||
@Override | ||
public void onTestFailedWithTimeout(ITestResult result) { | ||
listeners.stream() | ||
.filter(l-> l instanceof ITestListener) | ||
.map( l -> (ITestListener) l ) | ||
.forEach(l-> l.onTestFailedWithTimeout(result)); | ||
} | ||
|
||
@Override | ||
public void onFinish(ITestContext context) { | ||
listeners.stream() | ||
.filter(l-> l instanceof ITestListener) | ||
.map( l -> (ITestListener) l ) | ||
.forEach(l-> l.onFinish(context)); | ||
} | ||
} |
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