-
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.
- Loading branch information
1 parent
ac9d977
commit 50c08c0
Showing
11 changed files
with
248 additions
and
46 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/test/java/test/skip/github1632/AfterListenerSkipSample.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,29 @@ | ||
package test.skip.github1632; | ||
|
||
import org.testng.IInvokedMethod; | ||
import org.testng.IInvokedMethodListener; | ||
import org.testng.ITestResult; | ||
import org.testng.SkipException; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners(AfterListenerSkipSample.MySkipTestListener.class) | ||
public class AfterListenerSkipSample { | ||
|
||
@BeforeMethod | ||
void beforeMethod() { | ||
} | ||
|
||
@Test | ||
void shouldNotBeExecuted() { | ||
} | ||
|
||
public static class MySkipTestListener implements IInvokedMethodListener { | ||
|
||
@Override | ||
public void afterInvocation(IInvokedMethod method, ITestResult testResult) { | ||
throw new SkipException("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
24 changes: 24 additions & 0 deletions
24
src/test/java/test/skip/github1632/NoConfigAfterListenerSample.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,24 @@ | ||
package test.skip.github1632; | ||
|
||
import org.testng.IInvokedMethod; | ||
import org.testng.IInvokedMethodListener; | ||
import org.testng.ITestResult; | ||
import org.testng.SkipException; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners(NoConfigAfterListenerSample.MySkipTestListener.class) | ||
public class NoConfigAfterListenerSample { | ||
|
||
@Test | ||
void shouldNotBeExecuted() { | ||
} | ||
|
||
public static class MySkipTestListener implements IInvokedMethodListener { | ||
|
||
@Override | ||
public void afterInvocation(IInvokedMethod method, ITestResult testResult) { | ||
throw new SkipException("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,57 @@ | ||
package test_result; | ||
|
||
import org.testng.Assert; | ||
import org.testng.IInvokedMethod; | ||
import org.testng.IInvokedMethodListener; | ||
import org.testng.ITestResult; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners(AfterListenerSample.MySkipTestListener.class) | ||
public class AfterListenerSample { | ||
|
||
@Test | ||
public void failedTest() { | ||
} | ||
|
||
@Test(expectedExceptions = IllegalStateException.class, enabled = false) | ||
public void failedTest2() { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
@Test | ||
public void skippedTest() { | ||
} | ||
|
||
@Test | ||
public void succeedTest() { | ||
Assert.fail(); | ||
} | ||
|
||
@Test | ||
public void succeedTest2() { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
public static class MySkipTestListener implements IInvokedMethodListener { | ||
|
||
@Override | ||
public void afterInvocation(IInvokedMethod method, ITestResult result) { | ||
switch (method.getTestMethod().getMethodName()) { | ||
case "failedTest": | ||
case "failedTest2": | ||
result.setStatus(ITestResult.FAILURE); | ||
break; | ||
case "skippedTest": | ||
result.setStatus(ITestResult.SKIP); | ||
break; | ||
case "succeedTest": | ||
case "succeedTest2": | ||
result.setStatus(ITestResult.SUCCESS); | ||
break; | ||
default: | ||
throw new RuntimeException("Unknown method name: " + method.getTestMethod().getMethodName()); | ||
} | ||
} | ||
} | ||
} |
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,54 @@ | ||
package test_result; | ||
|
||
import org.testng.*; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners(BeforeListenerSample.MySkipTestListener.class) | ||
public class BeforeListenerSample { | ||
|
||
@Test | ||
public void failedTest() { | ||
} | ||
|
||
@Test(expectedExceptions = IllegalStateException.class, enabled = false) | ||
public void failedTest2() { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
@Test | ||
public void skippedTest() { | ||
} | ||
|
||
@Test | ||
public void succeedTest() { | ||
Assert.fail(); | ||
} | ||
|
||
@Test | ||
public void succeedTest2() { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
public static class MySkipTestListener implements IInvokedMethodListener { | ||
|
||
@Override | ||
public void beforeInvocation(IInvokedMethod method, ITestResult result) { | ||
switch (method.getTestMethod().getMethodName()) { | ||
case "failedTest": | ||
case "failedTest2": | ||
result.setStatus(ITestResult.FAILURE); | ||
break; | ||
case "skippedTest": | ||
result.setStatus(ITestResult.SKIP); | ||
break; | ||
case "succeedTest": | ||
case "succeedTest2": | ||
result.setStatus(ITestResult.SUCCESS); | ||
break; | ||
default: | ||
throw new RuntimeException("Unknown method name: " + method.getTestMethod().getMethodName()); | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...t_result/github1197/GitHub1197Sample.java → ...st/java/test_result/GitHub1197Sample.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package test_result.github1197; | ||
package test_result; | ||
|
||
import org.testng.Assert; | ||
import org.testng.ITestResult; | ||
|
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,62 @@ | ||
package test_result; | ||
|
||
import org.testng.TestNG; | ||
import org.testng.annotations.Test; | ||
import test.InvokedMethodNameListener; | ||
import test.SimpleBaseTest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ResultStatusTest extends SimpleBaseTest { | ||
|
||
@Test | ||
public void testGitHub1197() { | ||
TestNG tng = create(GitHub1197Sample.class); | ||
|
||
// A skipped method is not supposed to be run but, here, it's the goal of the feature | ||
InvokedMethodNameListener listener = new InvokedMethodNameListener(true, true); | ||
tng.addListener(listener); | ||
|
||
tng.run(); | ||
|
||
assertThat(listener.getSucceedMethodNames()).containsExactly("succeedTest", "succeedTest2"); | ||
assertThat(listener.getFailedBeforeInvocationMethodNames()).isEmpty(); | ||
assertThat(listener.getFailedMethodNames()).containsExactly("failedTest"); // , "failedTest2"); | ||
assertThat(listener.getSkippedMethodNames()).isEmpty(); | ||
assertThat(listener.getSkippedAfterInvocationMethodNames()).containsExactly("skippedTest"); | ||
} | ||
|
||
@Test | ||
public void testBeforeListener() { | ||
TestNG tng = create(BeforeListenerSample.class); | ||
|
||
// A skipped method is not supposed to be run but, here, it's the goal of the feature | ||
InvokedMethodNameListener listener = new InvokedMethodNameListener(true, true); | ||
tng.addListener(listener); | ||
|
||
tng.run(); | ||
|
||
assertThat(listener.getSucceedMethodNames()).containsExactly("succeedTest", "succeedTest2"); | ||
assertThat(listener.getFailedBeforeInvocationMethodNames()).isEmpty(); | ||
assertThat(listener.getFailedMethodNames()).containsExactly("failedTest"); // , "failedTest2"); | ||
assertThat(listener.getSkippedMethodNames()).isEmpty(); | ||
assertThat(listener.getSkippedAfterInvocationMethodNames()).containsExactly("skippedTest"); | ||
} | ||
|
||
@Test | ||
public void testAfterListener() { | ||
TestNG tng = create(AfterListenerSample.class); | ||
|
||
// A skipped method is not supposed to be run but, here, it's the goal of the feature | ||
InvokedMethodNameListener listener = new InvokedMethodNameListener(true, true); | ||
tng.addListener(listener); | ||
|
||
tng.run(); | ||
|
||
assertThat(listener.getSucceedMethodNames()).containsExactly("succeedTest", "succeedTest2"); | ||
assertThat(listener.getFailedBeforeInvocationMethodNames()).isEmpty(); | ||
assertThat(listener.getFailedMethodNames()).containsExactly("failedTest"); // , "failedTest2"); | ||
assertThat(listener.getSkippedMethodNames()).isEmpty(); | ||
assertThat(listener.getSkippedAfterInvocationMethodNames()).containsExactly("skippedTest"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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