Skip to content

Commit

Permalink
Assertion errors shown in the HTML report respect line breaks now (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Oct 14, 2016
1 parent 21b472f commit 7413263
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Custom annotations can now also be defined for the `@Table` annotation [#234](https://github.com/TNG/JGiven/issues/235)

## Small Improvements

* Assertion errors shown in the HTML report respect line breaks now. [#234](https://github.com/TNG/JGiven/issues/234)

# v0.12.1

## Fixed Issue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.tngtech.jgiven.examples;

import com.tngtech.jgiven.examples.tags.FailingOnPurpose;
import com.tngtech.jgiven.junit.SimpleScenarioTest;
import com.tngtech.jgiven.tags.Issue;
import org.junit.Test;

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

@FailingOnPurpose
public class FailingScenarioTest extends SimpleScenarioTest<FailingScenarioTest.Steps> {



@Test
@Issue("#234")
public void a_scenario_with_a_multi_line_error_message() {
given().multi_line_error_message();
}

public static class Steps {
public void multi_line_error_message() {
assertThat(true).as("This\nmessage\nhas\nmultiple lines").isFalse();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tngtech.jgiven.examples.coffeemachine;

import com.tngtech.jgiven.examples.tags.FailingOnPurpose;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -138,6 +139,7 @@ public void turned_off_machines_should_not_serve_coffee( boolean onOrOff ) {
}

@Test
@FailingOnPurpose
public void a_failing_scenario_for_demonstration_purposes() {
given().a_coffee_machine()
.and().there_are_no_more_coffees_left();
Expand All @@ -147,6 +149,7 @@ public void a_failing_scenario_for_demonstration_purposes() {
}

@Test
@FailingOnPurpose
@DataProvider( {
"true",
"false"
Expand Down Expand Up @@ -194,6 +197,7 @@ public void coffee_is_not_served( int coffees, int euros ) {
}
// end::dataprovider[]

@FailingOnPurpose
@Test( timeout = 1000 )
public void shouldFailWithUnexpectedRuntimeException() throws Exception {
then().$( "should throw a runtime exception", //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import com.tngtech.jgiven.examples.tags.FailingOnPurpose;
import org.junit.Test;
import org.testng.Assert;

Expand All @@ -26,6 +27,7 @@ public void a_scenario_with_nested_steps() {
}

@Test
@FailingOnPurpose
public void a_scenario_with_a_failing_nested_step_on_purpose() {

given().I_fill_out_the_registration_form_with_invalid_values();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tngtech.jgiven.examples.parameters;

import com.tngtech.jgiven.examples.tags.FailingOnPurpose;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -74,6 +75,7 @@ public static Object[][] manyValues() {
}

@Test
@FailingOnPurpose
@ExtendedDescription( "This scenario shows how large case tables are shown in JGiven. As soon as a table has more than 2 entries,"
+ " grouping by values is possible. This scenario also has some failing steps for demonstration purposes."
+ "<p>Btw. this description was created with the <a target='_blank' href='http://jgiven.org/javadoc/com/tngtech/jgiven/annotation/ExtendedDescription.html'>@ExtendedDescription</a> annotation" )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tngtech.jgiven.examples.tags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import com.tngtech.jgiven.annotation.IsTag;

@IsTag(description = "Scenarios that fail on purpose, to demonstrate how errors appear in JGiven")
@Retention( RetentionPolicy.RUNTIME )
public @interface FailingOnPurpose {
}
18 changes: 4 additions & 14 deletions jgiven-html5-report/src/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,8 @@ <h4 ng-hide="!currentPage.loading">Loading <i class="fa fa-circle-o-notch fa-spi
</tr>
</table>
<div ng-if="!scenario.casesAsTable">
<div ng-if="!case.success" data-alert
class="alert-box alert">
<span class="toggle" ng-click="case.stackTrace.expanded = !case.stackTrace.expanded">
<i class="fa fa-caret-right toggle {{case.stackTrace.expanded ? 'fa-rotate-90' : ''}}"></i>
FAILED: {{::case.errorMessage}}</span>

<pre ng-if="case.stackTrace.expanded">{{ ::case.stackTrace.join('\n') }}</pre>

<div ng-if="!case.success" data-alert class="alert-box alert">
<pre class="toggle" ng-click="case.stackTrace.expanded = !case.stackTrace.expanded"><i class="fa fa-caret-right toggle {{case.stackTrace.expanded ? 'fa-rotate-90' : ''}}"></i> FAILED: {{::case.errorMessage}}<span ng-if="case.stackTrace.expanded">{{ ::('\n'+case.stackTrace.join('\n')) }}</span></pre>
</div>
</div>

Expand Down Expand Up @@ -617,12 +611,8 @@ <h6 class="cases-table-header">Cases
</div>

<div ng-if="!case.success" data-alert class="alert-box alert">
<span class="toggle"
ng-click="case.stackTrace.expanded = !case.stackTrace.expanded">
<i class="fa fa-caret-right toggle {{case.stackTrace.expanded ? 'fa-rotate-90' : ''}}"></i>
FAILED: {{::case.errorMessage}}</span>
<pre ng-if="case.stackTrace.expanded">{{ ::case.stackTrace.join('\n') }}</pre>
<span ng-if="case.durationInNanos > 10000000"
<pre class="toggle" ng-click="case.stackTrace.expanded = !case.stackTrace.expanded"><i class="fa fa-caret-right toggle {{case.stackTrace.expanded ? 'fa-rotate-90' : ''}}"></i> FAILED: {{::case.errorMessage}}<span ng-if="case.stackTrace.expanded">{{ ::('\n'+case.stackTrace.join('\n')) }}</span></pre>
<span ng-if="case.durationInNanos > 10000000"
class="duration"> ({{ nanosToReadableUnit(case.durationInNanos) }})</span>
</div>
</div>
Expand Down

0 comments on commit 7413263

Please sign in to comment.