Skip to content

Commit

Permalink
JUnit: throwing an AssumptionViolationException will not lead to a fa…
Browse files Browse the repository at this point in the history
…iled scenario anymore. Instead, the scenario will be ignored and will not appear in the report at all. Fixes #185
  • Loading branch information
Jan Schäfer committed Feb 6, 2016
1 parent 397fccd commit cfff549
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
## Fixed Issues

* HTML Report: fixed an issue with the search input in the mobile menu that was hidden on mobile devices when the virtual keyboard appeared. [#182](https://github.com/TNG/JGiven/issues/182)
* JUnit: throwing an AssumptionViolationException will not lead to a failed scenario anymore. Instead, the scenario will be ignored and will not appear in the report at all. [#185](https://github.com/TNG/JGiven/issues/185)

# v0.11.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public void handleMethod( Object stageInstance, Method paramMethod, Object[] arg

@Override
public void handleThrowable( Throwable t ) throws Throwable {
if( t.getClass().getName().equals( "org.junit.AssumptionViolatedException" ) ) {
throw t;
}

listener.stepMethodFailed( t );
failed( t );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.tngtech.jgiven.junit;

import static org.assertj.core.api.Assertions.assertThat;

import org.assertj.core.api.Assertions;
import org.junit.AssumptionViolatedException;
import org.junit.Test;

import com.tngtech.jgiven.annotation.Description;
import com.tngtech.jgiven.junit.test.GivenTestStep;
import com.tngtech.jgiven.junit.test.ThenTestStep;
import com.tngtech.jgiven.junit.test.WhenTestStep;
import com.tngtech.jgiven.report.model.ScenarioCaseModel;
import com.tngtech.jgiven.report.model.StepStatus;

@Description( "Scenarios can have sections" )
public class AssumptionTest extends ScenarioTest<GivenTestStep, WhenTestStep, ThenTestStep> {

@Test
public void JUnit_assumption_exceptions_should_be_treated_correctly() throws Throwable {
try {
when().some_assumption_fails();
Assertions.fail( "AssumptionViolationException should have been thrown" );
} catch( AssumptionViolatedException e ) {}

getScenario().finished();

ScenarioCaseModel aCase = getScenario().getModel().getLastScenarioModel().getCase( 0 );
assertThat( aCase.getStep( 0 ).getStatus() ).isEqualTo( StepStatus.PASSED );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Assume;

import com.tngtech.jgiven.Stage;
import com.tngtech.jgiven.annotation.ExpectedScenarioState;
import com.tngtech.jgiven.annotation.ProvidedScenarioState;
Expand Down Expand Up @@ -29,4 +31,8 @@ public void something() {}
public void some_assertion_fails() {
assertThat( true ).isFalse();
}

public void some_assumption_fails() {
Assume.assumeTrue( false );
}
}

0 comments on commit cfff549

Please sign in to comment.