-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change exception handling for TestNG (#312)
- Loading branch information
1 parent
4481185
commit 8e83ddf
Showing
6 changed files
with
114 additions
and
11 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
39 changes: 39 additions & 0 deletions
39
jgiven-testng/src/test/java/com/tngtech/jgiven/testng/PendingTest.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,39 @@ | ||
package com.tngtech.jgiven.testng; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.tngtech.jgiven.annotation.Pending; | ||
import com.tngtech.jgiven.report.model.ExecutionStatus; | ||
import org.assertj.core.api.Assertions; | ||
import org.testng.SkipException; | ||
import org.testng.annotations.Test; | ||
|
||
import com.tngtech.jgiven.annotation.Description; | ||
import com.tngtech.jgiven.report.model.ScenarioCaseModel; | ||
import com.tngtech.jgiven.report.model.StepStatus; | ||
|
||
@Description( "Pending annotation is handled correctly" ) | ||
public class PendingTest extends SimpleScenarioTest<TestNgTest.TestSteps> { | ||
|
||
@Test | ||
@Pending | ||
public void pending_annotation_should_catch_exceptions() { | ||
given().something(); | ||
when().something_fails(); | ||
then().nothing_happens(); | ||
|
||
ScenarioCaseModel aCase = getScenario().getScenarioCaseModel(); | ||
assertThat( aCase.getExecutionStatus() ).isEqualTo( ExecutionStatus.SCENARIO_PENDING ); | ||
} | ||
|
||
@Test | ||
public void pending_annotation_on_failing_steps_should_catch_exceptions() { | ||
given().something(); | ||
when().something_fails_with_pending_annotation(); | ||
then().nothing_happens(); | ||
|
||
ScenarioCaseModel aCase = getScenario().getScenarioCaseModel(); | ||
assertThat( aCase.getExecutionStatus() ).isEqualTo( ExecutionStatus.SOME_STEPS_PENDING ); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
jgiven-testng/src/test/java/com/tngtech/jgiven/testng/RetryTest.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 com.tngtech.jgiven.testng; | ||
|
||
import org.testng.IRetryAnalyzer; | ||
import org.testng.ITestResult; | ||
import org.testng.annotations.Test; | ||
|
||
@Test | ||
public class RetryTest extends SimpleScenarioTest<TestNgTest.TestSteps> { | ||
|
||
int count = 0; | ||
|
||
@Test(retryAnalyzer = MyAnalyzer.class) | ||
public void failing_with_retry_test() { | ||
when().something_should_$_fail(count++ == 0); | ||
} | ||
|
||
public static class MyAnalyzer implements IRetryAnalyzer { | ||
int count = 0; | ||
@Override | ||
public boolean retry(ITestResult result) { | ||
return count++ == 0; | ||
} | ||
} | ||
} |
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