Skip to content

Commit

Permalink
feat(Issue-1625): Introduce new ABORTED status
Browse files Browse the repository at this point in the history
adapt unit tests

Signed-off-by: l-1squared <30831153+l-1squared@users.noreply.github.com>
  • Loading branch information
l-1squared committed Jun 17, 2024
1 parent 99f9418 commit 86c00fc
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void stepMethodFailed(Throwable t) {
@Override
public void stepMethodAborted(Throwable t) {
if (currentStep != null) {
currentStep.setStatus(StepStatus.SKIPPED);
currentStep.setStatus(StepStatus.ABORTED);
}
}

Expand Down Expand Up @@ -377,7 +377,7 @@ public void scenarioFailed(Throwable e) {

@Override
public void scenarioAborted(Throwable e){
setStatus(ExecutionStatus.SOME_STEPS_PENDING);
setStatus(ExecutionStatus.ABORTED);
setException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum ExecutionStatus {
SCENARIO_PENDING,
SUCCESS,
FAILED,
ABORTED,
SOME_STEPS_PENDING;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum StepStatus {
PASSED,
FAILED,
SKIPPED,
PENDING;
PENDING,
ABORTED;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import java.lang.reflect.Field;
import java.util.*;

import static com.tngtech.jgiven.report.model.ExecutionStatus.FAILED;
import static com.tngtech.jgiven.report.model.ExecutionStatus.SUCCESS;
import static com.tngtech.jgiven.report.model.ExecutionStatus.*;
import static java.lang.String.format;
import static org.junit.Assume.assumeTrue;

Expand Down Expand Up @@ -87,7 +86,7 @@ protected void succeeded() throws Throwable {
scenario.finished();

// ignore test when scenario is not implemented
assumeTrue( EnumSet.of( SUCCESS, FAILED ).contains( scenario.getScenarioModel().getExecutionStatus() ) );
assumeTrue( EnumSet.of( SUCCESS, FAILED, ABORTED).contains( scenario.getScenarioModel().getExecutionStatus() ) );
}

protected void failed( Throwable e ) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
package com.tngtech.jgiven.junit;

import com.tngtech.jgiven.annotation.AfterScenario;
import com.tngtech.jgiven.annotation.Description;
import com.tngtech.jgiven.report.model.ScenarioCaseModel;
import com.tngtech.jgiven.report.model.StepStatus;
import org.junit.After;
import org.junit.Assume;
import org.junit.AssumptionViolatedException;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assumptions.assumeThat;

@Description("Scenarios can have sections")
@Description("Scenarios can have assumptions")
public class AssumptionTest extends SimpleScenarioTest<AssumptionTest.TestStage> {


@Test
public void should_pass_on_assertJ_assumptions() throws Throwable {
assertThatThrownBy(() -> when().I_assume_something_using_assertJ())
.isInstanceOf(catchException(AssumptionTest::assertJAssumptionFailure));
public void should_report_aborted_on_assertJ_assumptions() throws Throwable {
when().I_assume_something_using_assertJ();
getScenario().finished();

assertThat(getScenario().getExecutor().hasAborted()).isTrue();
assertThat(getScenario().getExecutor().getAbortedException()).isInstanceOf(AssumptionViolatedException.class);
ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase(0);
assertThat(aCase.getStep(0).getStatus()).isEqualTo(StepStatus.PASSED);
assertThat(aCase.getStep(0).getStatus()).isEqualTo(StepStatus.ABORTED);
}

@Test
public void should_pass_on_junit5_assumptions() throws Throwable {
assertThatThrownBy(() -> when().I_assume_something_using_junit5())
.isInstanceOf(catchException(AssumptionTest::junitAssumptionFailure));
public void should_report_aborted_on_junit_assumptions() throws Throwable {
when().I_assume_something_using_junit5();
getScenario().finished();

assertThat(getScenario().getExecutor().hasAborted()).isTrue();
assertThat(getScenario().getExecutor().getAbortedException()).isInstanceOf(org.junit.AssumptionViolatedException.class);
ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase(0);
assertThat(aCase.getStep(0).getStatus()).isEqualTo(StepStatus.PASSED);
assertThat(aCase.getStep(0).getStatus()).isEqualTo(StepStatus.ABORTED);
}

static class TestStage {
Expand All @@ -50,13 +57,4 @@ private static void assertJAssumptionFailure() {
private static void junitAssumptionFailure() {
Assume.assumeTrue(false);
}

private Class<? extends Exception> catchException(Runnable runnable) {
try {
runnable.run();
return null;
} catch (Exception e) {
return e.getClass();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.tngtech.jgiven.junit5;

import static com.tngtech.jgiven.report.model.ExecutionStatus.FAILED;
import static com.tngtech.jgiven.report.model.ExecutionStatus.SUCCESS;

import com.tngtech.jgiven.base.ScenarioTestBase;
import com.tngtech.jgiven.config.AbstractJGivenConfiguration;
import com.tngtech.jgiven.config.ConfigurationUtil;
Expand All @@ -24,6 +21,8 @@
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;

import static com.tngtech.jgiven.report.model.ExecutionStatus.*;

/**
* This extension enables JGiven for JUnit 5 Tests.
* <p>
Expand Down Expand Up @@ -93,7 +92,7 @@ public void afterTestExecution(ExtensionContext context) throws Exception {

// ignore test when scenario is not implemented
Assumptions.assumeTrue(
EnumSet.of(SUCCESS, FAILED).contains(scenario.getScenarioModel().getExecutionStatus()));
EnumSet.of(SUCCESS, FAILED, ABORTED).contains(scenario.getScenarioModel().getExecutionStatus()));

} catch (Exception e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@ class AssumptionsTest extends SimpleScenarioTest<AssumptionsTest.TestStage> {

@Test
void should_pass_on_assertJ_assumptions() throws Throwable {
assertThatThrownBy(() -> when().I_assume_something_using_assertJ())
.isInstanceOf(catchException(AssumptionsTest::assertJAssumptionFailure));
when().I_assume_something_using_assertJ();
getScenario().finished();
ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase( 0 );
assertThat( aCase.getStep( 0 ).getStatus() ).isEqualTo( StepStatus.PASSED );

assertThat(getScenario().getExecutor().hasAborted()).isTrue();
assertThat(getScenario().getExecutor().getAbortedException()).isInstanceOf(org.junit.AssumptionViolatedException.class);
ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase(0);
assertThat(aCase.getStep(0).getStatus()).isEqualTo(StepStatus.ABORTED);
}

@Test
void should_pass_on_junit5_assumptions() throws Throwable {
assertThatThrownBy(() -> when().I_assume_something_using_junit5())
.isInstanceOf(catchException(AssumptionsTest::junitAssumptionFailure));
when().I_assume_something_using_junit5();
getScenario().finished();
ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase( 0 );
assertThat( aCase.getStep( 0 ).getStatus() ).isEqualTo( StepStatus.PASSED );

assertThat(getScenario().getExecutor().hasAborted()).isTrue();
assertThat(getScenario().getExecutor().getAbortedException()).isInstanceOf(org.opentest4j.TestAbortedException.class);
ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase(0);
assertThat(aCase.getStep(0).getStatus()).isEqualTo(StepStatus.ABORTED);
}

static class TestStage {
Expand All @@ -48,12 +52,4 @@ private static void assertJAssumptionFailure(){
private static void junitAssumptionFailure(){
Assumptions.abort();
}
private Class<? extends Exception> catchException(Runnable runnable) {
try {
runnable.run();
return null;
} catch (Exception e) {
return e.getClass();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void should_pass_on_assertJ_assumptions() throws Throwable {
.isInstanceOf(catchException(AssumptionsTest::assertJAssumptionFailure));
getScenario().finished();
ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase( 0 );
assertThat( aCase.getStep( 0 ).getStatus() ).isEqualTo( StepStatus.PASSED );
assertThat( aCase.getStep( 0 ).getStatus() ).isEqualTo( StepStatus.ABORTED);
}

@Test
Expand All @@ -28,7 +28,7 @@ public void should_pass_on_testng_assumptions() throws Throwable {
.isInstanceOf(catchException(AssumptionsTest::testNgAssumptionFailure));
getScenario().finished();
ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase( 0 );
assertThat( aCase.getStep( 0 ).getStatus() ).isEqualTo( StepStatus.PASSED );
assertThat( aCase.getStep( 0 ).getStatus() ).isEqualTo( StepStatus.ABORTED);
}

static class TestStage {
Expand Down

0 comments on commit 86c00fc

Please sign in to comment.