SpecResults
SpecResults copied to clipboard
Object reference not set to an instance of an object.
I setup my project just like in the example but keep on getting this exception.
I am using VS 2013, Win 8.1 64bit
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=TechTalk.SpecFlow
StackTrace:
Server stack trace:
at SpecFlow.Reporting.Reporters.ExecuteStep(Action action, MethodBase methodBase, Object[] args)
at SpecFlow.Reporting.ReportingMessageSink.SyncProcessMessage(IMessage msg)
at System.Runtime.Remoting.Lifetime.LeaseSink.SyncProcessMessage(IMessage msg)
at System.Runtime.Remoting.Messaging.ServerContextTerminatorSink.SyncProcessMessage(IMessage reqMsg)
at System.Runtime.Remoting.Channels.CrossContextChannel.SyncProcessMessageCallback(Object[] args)
at System.Threading.Thread.CompleteCrossContextCallback(InternalCrossContextDelegate ftnToCall, Object[] args)
at System.Threading.Thread.InternalCrossContextCallback(Context ctx, IntPtr ctxID, Int32 appDomainID, InternalCrossContextDelegate ftnToCall, Object[] args)
at System.Runtime.Remoting.Channels.CrossContextChannel.SyncProcessMessage(IMessage reqMsg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Taf.Workflow.TestSpec.Steps.TestSpecificationSteps.GivenIHaveATestSpecificationTERev(String testspecificationId, String revision, String testing)
at lambda_method(Closure , IContextManager , String , String , String )
at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
at Taf.Example.Workflow.WorkflowFeature.ScenarioCleanup() in c:\Project\meccano\branch\tools\specbyexample\tests\Taf.Example.Workflow\Workflow.Simple.feature.cs:line 0
at Taf.Example.Workflow.WorkflowFeature.SimpleTestSpecificationModification2() in c:\Project\meccano\branch\tools\specbyexample\tests\Taf.Example.Workflow\Workflow.Simple.feature:line 6
InnerException:
In order to get SpecResults to work across the board, what I did was create a hook class that enherits > ReportingStepDefinitions
Create a static method with an attribute : BeforeTestRun Inside the method you would choose which report structure you want (I use JSON): Reporters.Add(new JsonReporter());
You will need to import > using SpecResults; using SpecResults.Json;
Then, create another static method within the hook class with either attributes: AfterScenario/AfterFeature
For AfterScenario: [AfterScenario] public static void AfterScenarioRun() { Reporters.FinishedScenario += (sender, args) => { //Console.WriteLine(args.Reporter.WriteToString()); var serializedReport = JsonConvert.SerializeObject(args.Reporter); //Console.Write(String.Format("{0}", JsonConvert.DeserializeObject(serializedReport))); //Console.Write("\nEnd."); }; }
For AfterFeature: [AfterFeature] public static void AfterFeatureRun() { Reporters.FinishedFeature += (sender, args) => { //Console.WriteLine(args.Reporter.WriteToString()); var serializedReport = JsonConvert.SerializeObject(args.Reporter); Console.Write(String.Format("{0}", JsonConvert.DeserializeObject(serializedReport))); Console.Write("\nEnd."); }; }
Notice the difference of Reporter.FinishedFeature & Reporter.FinishedScenario
Hope this helps.