-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #827 from TNG/feature/Issue-373-Improve-testing-fo…
…r-jupiter Feature/issue 373 improve testing for jupiter
- Loading branch information
Showing
31 changed files
with
650 additions
and
206 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
13 changes: 13 additions & 0 deletions
13
jgiven-tests/src/main/java/com/tngtech/jgiven/tags/FeatureJUnit5.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,13 @@ | ||
package com.tngtech.jgiven.tags; | ||
|
||
import com.tngtech.jgiven.annotation.IsTag; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@FeatureTestFramework | ||
@IsTag( name = "JUnit5", | ||
description = "Tests can be be executed with JUnit5" ) | ||
@Retention( RetentionPolicy.RUNTIME ) | ||
public @interface FeatureJUnit5 { | ||
|
||
} |
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
35 changes: 35 additions & 0 deletions
35
jgiven-tests/src/main/java/com/tngtech/jgiven/tests/JGivenReportExtractingExtension.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,35 @@ | ||
package com.tngtech.jgiven.tests; | ||
|
||
import com.tngtech.jgiven.exception.JGivenWrongUsageException; | ||
import com.tngtech.jgiven.impl.ScenarioBase; | ||
import com.tngtech.jgiven.impl.ScenarioHolder; | ||
import com.tngtech.jgiven.junit5.JGivenExtension; | ||
import com.tngtech.jgiven.report.model.ReportModel; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
/** | ||
* Extracts the report Model from within the Test context before it gets deleted. | ||
*/ | ||
public class JGivenReportExtractingExtension extends JGivenExtension { | ||
|
||
private static final Map<Class<?>, ReportModel> modelHolder = new ConcurrentHashMap<>(); | ||
|
||
public static Optional<ReportModel> getReportModelFor(Class<?> testClass) { | ||
return Optional.ofNullable(modelHolder.get(testClass)); | ||
} | ||
|
||
|
||
@Override | ||
public void afterTestExecution(ExtensionContext context) throws Exception { | ||
Class<?> testClass = context.getTestClass() | ||
.orElseThrow(() -> new JGivenWrongUsageException("tests without test class are not supported yet")); | ||
Optional.ofNullable(ScenarioHolder.get()) | ||
.map(ScenarioHolder::getScenarioOfCurrentThread) | ||
.map(ScenarioBase::getModel) | ||
.ifPresent(model -> modelHolder.put(testClass, model)); | ||
super.afterTestExecution(context); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
jgiven-tests/src/main/java/com/tngtech/jgiven/tests/JUnit5AfterMethodTests.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,48 @@ | ||
package com.tngtech.jgiven.tests; | ||
|
||
import com.tngtech.jgiven.base.ScenarioTestBase; | ||
import com.tngtech.jgiven.impl.Scenario; | ||
import com.tngtech.jgiven.report.model.ScenarioCaseModel; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@ExtendWith(JGivenReportExtractingExtension.class) | ||
public class JUnit5AfterMethodTests extends ScenarioTestBase<GivenTestStage, WhenTestStage, ThenTestStage> { | ||
|
||
private final Scenario<GivenTestStage, WhenTestStage, ThenTestStage> scenario = createScenario(); | ||
|
||
@Override | ||
public Scenario<GivenTestStage, WhenTestStage, ThenTestStage> getScenario() { | ||
return scenario; | ||
} | ||
|
||
@Test | ||
public void a_failing_JUnit_5_test() { | ||
given().nothing(); | ||
when().a_step_fails(); | ||
then().something_happened(); | ||
} | ||
|
||
@Test | ||
public void a_succeeding_JUnit5_test() { | ||
given().nothing(); | ||
when().something_happens(); | ||
then().something_happened(); | ||
} | ||
|
||
@Test | ||
@Disabled | ||
public void a_skipped_JUnit5_test() { | ||
given().nothing(); | ||
when().something_happens(); | ||
then().something_happened(); | ||
} | ||
|
||
|
||
@AfterEach | ||
public void modifyScenario() { | ||
getScenario().getModel().getLastScenarioModel().addCase(new ScenarioCaseModel()); | ||
} | ||
} |
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
8 changes: 5 additions & 3 deletions
8
jgiven-tests/src/main/java/com/tngtech/jgiven/tests/TestClassWithDescription.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
9 changes: 6 additions & 3 deletions
9
jgiven-tests/src/main/java/com/tngtech/jgiven/tests/TestClassWithOnlyIgnoredTests.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
Oops, something went wrong.