JBehave
  1. JBehave
  2. JBEHAVE-931

Stats are incorrect when executing a story with a given story

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 3.8
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
    • Environment:
      Windows 7
      Java 6u41
      Maven 3.0.4
    • Patch Submitted:
      Yes
    • Number of attachments :
      2

      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:

      PostStoryStatisticsCollector.java
      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;
      		}
      		....
      	}
      }
      

        Activity

        There are no entries against this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Stefan Leonhartsberger
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: