Skip to content

Commit

Permalink
Handle TestNG SkipException correctly, fixes #355
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Jul 28, 2018
1 parent ea411a0 commit fe0975f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ private void handleMethod( Object stageInstance, Method paramMethod, Object[] ar
}

private void handleThrowable( Throwable t ) throws Throwable {
if( t.getClass().getName().equals( "org.junit.AssumptionViolatedException" ) ) {
if( t.getClass().getName().equals( "org.junit.AssumptionViolatedException" ) ||
t.getClass().getName().equals( "org.testng.SkipException")) {
throw t;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.tngtech.jgiven.testng;

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

import org.assertj.core.api.Assertions;

import com.tngtech.jgiven.annotation.Description;
import com.tngtech.jgiven.report.model.ScenarioCaseModel;
import com.tngtech.jgiven.report.model.StepStatus;
import org.testng.SkipException;
import org.testng.annotations.Test;

@Description( "SkipException are handled correctly" )
public class SkipExceptionTest extends SimpleScenarioTest<TestNgTest.TestSteps> {

@Test
public void TestNG_skipped_exceptions_should_be_treated_correctly() throws Throwable {
try {
given().skipped_exception_is_thrown();
Assertions.fail( "SkipException should have been thrown" );
} catch( SkipException 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 @@ -115,5 +115,9 @@ public void mixed_with( String something ) {}

public void something() {}

public void skipped_exception_is_thrown() {
throw new org.testng.SkipException( "should be skipped" );
}

}
}

0 comments on commit fe0975f

Please sign in to comment.