Skip to content

Commit

Permalink
feat(Issue-1625): write example tests for aborted scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
l-1squared committed Aug 5, 2024
1 parent 96b6ee1 commit e9aeb93
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.tngtech.jgiven.examples.assumptions;

import com.tngtech.jgiven.annotation.ScenarioStage;
import com.tngtech.jgiven.junit.JGivenClassRule;
import com.tngtech.jgiven.junit.JGivenMethodRule;
import org.junit.Assume;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

@SuppressWarnings("NewClassNamingConvention")
public class AssumptionFailureTestScenarios {

@ClassRule
public static final JGivenClassRule writerRule = new JGivenClassRule();

@Rule
public final JGivenMethodRule scenarioRule = new JGivenMethodRule();

@ScenarioStage
AssumptionFailureTestStage givenTestStage;

@SuppressWarnings("DataFlowIssue")
@Test
public void test_with_failing_assumption() {
Assume.assumeFalse(true);
}

@Test
public void test_with_failing_assumption_in_stage() {
givenTestStage.given().a_failed_junit_assumption().and()
.nothing();

}

@Test
public void test_with_failing_assumption_in_second_stage(){
givenTestStage.given().nothing().and()
.a_failed_junit_assumption();
}

@Test
public void test_with_failing_assumption_in_a_nested_stage(){
givenTestStage.given().nothing().a_failed_nested_step().and().nothing();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.tngtech.jgiven.examples.assumptions;

import com.tngtech.jgiven.Stage;
import com.tngtech.jgiven.annotation.NestedSteps;
import org.junit.Assume;

public class AssumptionFailureTestStage extends Stage<AssumptionFailureTestStage> {

public AssumptionFailureTestStage nothing() {
return self();
}

@SuppressWarnings("DataFlowIssue") //fail on purpose
public AssumptionFailureTestStage a_failed_junit_assumption() {
Assume.assumeFalse(true);
return self();
}

@NestedSteps
public AssumptionFailureTestStage a_failed_nested_step() {
self().a_failed_junit_assumption();
return self();
}
}

0 comments on commit e9aeb93

Please sign in to comment.