Skip to content

Commit

Permalink
add exception type to error message in the report (fixes #154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Dec 19, 2015
1 parent 75b01d4 commit bec4b27
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Steps can now have nested steps that are shown in the report. This is done by an
### Other

* HTML Report: case tables have sortable columns now [#175](https://github.com/TNG/JGiven/pull/175)
* Exception type is now added to the error message of a failed step [#154](https://github.com/TNG/JGiven/issues/154)

## Fixed Issues

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void setSuccess( boolean success ) {
}

public void setException( Throwable throwable ) {
scenarioCaseModel.setErrorMessage( throwable.getMessage() );
scenarioCaseModel.setErrorMessage( throwable.getClass().getName() + ": " + throwable.getMessage() );
scenarioCaseModel.setStackTrace( getStackTrace( throwable, FILTER_STACK_TRACE ) );
}

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.junit.Test;

import com.tngtech.jgiven.Stage;
import com.tngtech.jgiven.StepFunction;

public class ExceptionReportingTest extends SimpleScenarioTest<ExceptionReportingTest.TestSteps> {

@Test
public void exception_type_is_contained_in_the_report() throws Throwable {
when().$( "Something", new StepFunction<TestSteps>() {
@Override
public void apply( TestSteps testSteps ) throws Exception {
throw new IllegalStateException( "failing state for testing" );
}
} );

try {
getScenario().finished();
} catch( IllegalStateException ignore ) {}

String errorMessage = getScenario().getScenarioModel().getCase( 0 ).getErrorMessage();
assertThat( errorMessage ).isEqualTo( "java.lang.IllegalStateException: failing state for testing" );
}

public static class TestSteps extends Stage<TestSteps> {

}
}

0 comments on commit bec4b27

Please sign in to comment.