Details
Description
Execute a story with a given story:
The given story contains 2 scenarios, where one of them fails
The acutal story contains only 1 scenario
Expected: The stats look like can be seen from StatsCorrect.png
Reveived: The stats look like can be seen from StatsError.png
Cause can be found in PostStoryStatisticsCollector:
The method writeData uses the output OutputStream to write the properties to the stats file.
This method is called for both stories: the given and the actual one.
However the output Outputstream is closed after the first writingData call and therefore cannot write any other data to the stats file.
Moreover in the afterStory method there is call to add("scenarioFailed") for a given story, which also causes wrong stats. This should be commented out.
It would also be nice to change the access modifier of methods like add, has, .. to public in order to let people easily add their own statistics.
Suggestions for closing the bug:
private boolean isClosed = false; private void writeData() { if(isClosed){ //Recreate outputstream if already closed .... getOutputFile() has to be created also output = new FilePrintStreamFactory.FilePrintStream(output.getOutputFile(), false); isClosed = false; } Properties p = new Properties(); for(String event : data.keySet()) { if (!event.startsWith("current")) { p.setProperty(event, data.get(event).toString()); } } try { p.store(output, this.getClass().getName()); } catch (IOException e) { e.printStackTrace(); } finally { //Put close to finally in order to also close the stream in case of an error output.close(); isClosed = true; } } public void afterStory(boolean givenStory) { boolean write = false; if (givenStory) { this.givenStories--; if ( has("stepsFailed") ){ // What is this used for? --> causes stats error --> at least givenStoryScenarioFailed should be called? //add("scenariosFailed"); write = true; } .... } }