timschlechter / SpecResults

Get better feedback from your SpecFlow testsuite
http://specflowreporting.azurewebsites.net/
MIT License
23 stars 18 forks source link

SpecResults/SpecResults/Reporters.ExecuteStep(Action, MethodBase, object[]) stepContainer #14

Open MilkyWayJoe opened 9 years ago

MilkyWayJoe commented 9 years ago

Just reporting as I don't have a PR ready for this.

I have found this piece of code that doesn't seem to be doing anything in particular, and also being discarded on the next line:

methodBase = methodBase ?? action.Method;
var currentSteps = new Dictionary<Reporter, Step>();
var starttime = CurrentRunTime;
foreach(var reporter in GetAll()) {
    currentSteps.Add(reporter, reporter.CurrentStep);

    var step = CreateStep(starttime, methodBase, args);
    // what is this supposed to do?
    var stepContainer = reporter.CurrentStep ?? reporter.CurrentScenarioBlock;
    stepContainer.Steps.Add(step); // stepContainer is not used again
    reporter.CurrentStep = step;
    OnStartedStep(reporter);
}

This is the same line that causes most of the reported object reference is not set to an instance of an object issues. Removing this will solve this issue, however, it will introduce other issues: The reports take internal TearDown as part of the test and tries to execute reporting on clean up.

During TearDown, reporter won't have a CurrentStep and stepContainer will be null and crashing the test execution. I don't know if this is because of my setup as I have the BeforeTestRun in an abstract class (BaseStep) which inherits from ReportingStepDefinitions and all my steps inherit from the BaseStep abstract class.

kerly commented 8 years ago

@MilkyWayJoe I was having this issue as well and I found a fix that worked for me. This error was only happening when I was trying to run the feature files from projects other than the initial project I created (with the feature files / steps classes). When I added the SpecFlow package / SpecFlow config to the project that runs the feature files, everything works fine.

Example config:

  <specFlow>
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
    <unitTestProvider name="NUnit" />
    <stepAssemblies>
      <stepAssembly assembly="SpecResults" />
    </stepAssemblies>
  </specFlow>