-
Notifications
You must be signed in to change notification settings - Fork 98
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
23a23fc
commit 7efcb8f
Showing
9 changed files
with
213 additions
and
55 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
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
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 | ||
@Pending(executeSteps = true) | ||
public void pending_annotation_should_catch_exceptions_when_executing_steps() { | ||
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
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
Oops, something went wrong.