Skip to content

Commit

Permalink
Merge pull request #137 from trivago/1.7.2-bugfix
Browse files Browse the repository at this point in the history
1.7.2 bugfix
  • Loading branch information
Benjamin Bischoff authored Mar 5, 2019
2 parents d046974 + 20d4140 commit 7063846
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [1.7.2] - 2019-03-05

### Fixed

* Step times did not take step hook times into account (#135)

## [1.7.1] - 2019-02-28

### Fixed
Expand All @@ -20,9 +26,11 @@ Back to [Readme](README.md).
* Feature name link is now shown on scenario detail pages (#125)
* three new options to expand or collapse hooks and docstrings on scenario detail pages (default: false) (#117)
```xml
<configuration>
<expandBeforeAfterHooks>true|false</expandBeforeAfterHooks>
<expandStepHooks>true|false</expandStepHooks>
<expandDocStrings>true|false</expandDocStrings>
</configuration>
```

* Added data attributes for common elements (`data-cluecumber-item`) to simplify custom css configurations (related to #129)
Expand Down Expand Up @@ -359,6 +367,7 @@ Back to [Readme](README.md).

Initial project version on GitHub and Maven Central.

[1.7.2]: https://github.com/trivago/cluecumber-report-plugin/tree/1.7.2
[1.7.1]: https://github.com/trivago/cluecumber-report-plugin/tree/1.7.1
[1.7.0]: https://github.com/trivago/cluecumber-report-plugin/tree/1.7.0
[1.6.5]: https://github.com/trivago/cluecumber-report-plugin/tree/1.6.5
Expand Down
6 changes: 3 additions & 3 deletions example-project/json/scenario_with_step_hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"before": [
{
"result": {
"duration": 6236342,
"duration": 10000000,
"status": "passed"
},
"match": {
Expand All @@ -63,7 +63,7 @@
}
],
"result": {
"duration": 5466433151,
"duration": 40000000,
"status": "passed"
},
"line": 6,
Expand All @@ -87,7 +87,7 @@
],
"result": {
"error_message": "some.AssertError: some stack trace for the after step hook\r\n",
"duration": 6236342,
"duration": 20000000,
"status": "failed"
},
"match": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public long getTotalDuration() {
totalDurationMicroseconds += beforeStep.getResult().getDuration();
}
for (Step step : steps) {
totalDurationMicroseconds += step.getResult().getDuration();
totalDurationMicroseconds += step.getTotalDuration();
}
for (ResultMatch afterStep : after) {
totalDurationMicroseconds += afterStep.getResult().getDuration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.trivago.cluecumber.json.pojo;

import com.google.gson.annotations.SerializedName;
import com.trivago.cluecumber.rendering.RenderingUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -100,4 +101,21 @@ public DocString getDocString() {
public void setDocString(final DocString docString) {
this.docString = docString;
}

public long getTotalDuration() {
long totalDurationMicroseconds = 0;

for (ResultMatch beforeStep : before) {
totalDurationMicroseconds += beforeStep.getResult().getDuration();
}
totalDurationMicroseconds += getResult().getDuration();
for (ResultMatch afterStep : after) {
totalDurationMicroseconds += afterStep.getResult().getDuration();
}
return totalDurationMicroseconds;
}

public String returnTotalDurationString() {
return RenderingUtils.convertMicrosecondsToTimeString(getTotalDuration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ preheadlineLink="pages/feature-scenarios/feature_${element.featureIndex?c}.html"
</span>
</div>
<div class="col-2 text-left small">
${step.result.returnDurationString()}
${step.returnTotalDurationString()}
</div>
<div class="col-1 text-right">
<@common.status status=step.consolidatedStatusString/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,21 @@ public void getConsolidatedStatusTest() {
assertThat(resultMatch.getConsolidatedStatus(), is(Status.PASSED));
assertThat(resultMatch.getConsolidatedStatusString(), is("passed"));
}

@Test
public void hasOutputsTest(){
assertThat(resultMatch.hasOutputs(), is(false));
List<String> output = new ArrayList<>();
output.add("Test");
resultMatch.setOutput(output);
assertThat(resultMatch.hasOutputs(), is(true));
}

@Test
public void returnEscapedOutputsTest(){
List<String> output = new ArrayList<>();
output.add("Testäöüß");
resultMatch.setOutput(output);
assertThat(resultMatch.returnEscapedOutputs().get(0), is("Testäöüß"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.trivago.cluecumber.json.pojo;

import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -47,4 +48,33 @@ public void returnNameWithArguments() {
step.setResult(result);
assertThat(step.returnNameWithArguments(), is("This is a name with an <strong>argument</strong> inside."));
}

@Test
public void totalDurationTest() {
Step step = new Step();

List<com.trivago.cluecumber.json.pojo.ResultMatch> beforeSteps = new ArrayList<>();
com.trivago.cluecumber.json.pojo.ResultMatch before = new com.trivago.cluecumber.json.pojo.ResultMatch();
Result beforeResult = new Result();
beforeResult.setDuration(1000000000L);
before.setResult(beforeResult);
beforeSteps.add(before);
step.setBefore(beforeSteps);

Result stepResult = new Result();
stepResult.setDuration(5000000000L);
step.setResult(stepResult);

List<com.trivago.cluecumber.json.pojo.ResultMatch> afterSteps = new ArrayList<>();
com.trivago.cluecumber.json.pojo.ResultMatch after = new com.trivago.cluecumber.json.pojo.ResultMatch();
Result afterResult = new Result();
afterResult.setDuration(2000000000L);
after.setResult(afterResult);
afterSteps.add(after);
step.setAfter(afterSteps);

MatcherAssert.assertThat(step.getTotalDuration(), is(8000000000L));
MatcherAssert.assertThat(step.returnTotalDurationString(), is("0m 08s 000ms"));
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.trivago.cluecumber.rendering;

import com.trivago.cluecumber.exceptions.CluecumberPluginException;
import freemarker.template.Template;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class TemplateConfigurationTest {

private TemplateConfiguration templateConfiguration;
Expand All @@ -22,4 +26,11 @@ public void validInitTest() {
public void getNonexistentTemplateTest() throws CluecumberPluginException {
templateConfiguration.getTemplate("testTemplate");
}

@Test
public void getExistentTemplateTest() throws CluecumberPluginException {
templateConfiguration.init("/");
Template template = templateConfiguration.getTemplate("test");
assertThat(template.toString(), is("${test}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class AllScenariosPageCollectionTest {

Expand Down Expand Up @@ -63,6 +65,26 @@ public void getTotalDurationDefaultValueTest() {
assertThat(totalDuration, is(0L));
}

@Test
public void getTotalDurationTest() {
Report report = mock(Report.class);
when(report.getTotalDuration()).thenReturn(5000000000L);
Report[] reports = new Report[]{report, report};

allScenariosPageCollection.addReports(reports);
long totalDuration = allScenariosPageCollection.getTotalDuration();
assertThat(totalDuration, is(10000000000L));
}

@Test
public void getTotalDurationStringTest() {
Report report = mock(Report.class);
when(report.getTotalDuration()).thenReturn(5000000000L);
Report[] reports = new Report[]{report};
allScenariosPageCollection.addReports(reports);
assertThat(allScenariosPageCollection.getTotalDurationString(), is("0m 05s 000ms"));
}

@Test
public void hasFailedScenariosTest() {
assertThat(allScenariosPageCollection.hasFailedScenarios(), is(false));
Expand Down
1 change: 1 addition & 0 deletions plugin-code/src/test/resources/test.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${test}

0 comments on commit 7063846

Please sign in to comment.