0

I have these SpecFlow step definitions:

    [Given(@"I am on the (.*) page")]
    public void GivenIAmOnThePage(string url)
    {
        Given(@"I go to https://daringfireball.net/ page");
    }

    [Given(@"I go to (.*) page")]
    public void GivenIGoToPage(string url)
    {
        // nothing
    }

When I run the test the step executes just fine but an error is thrown at the end of the test run:

------ Discover test started ------
NUnit Adapter 3.10.0.21: Test discovery starting
Assembly contains no NUnit 3.0 tests: C:\git\MyProj.Tests\bin\Debug\MyProj.Tests.dll
NUnit Adapter 3.10.0.21: Test discovery complete
[xUnit.net 00:00:00.3975558]   Discovering: MyProj.Tests
[xUnit.net 00:00:00.8475597]   Discovered:  MyProj.Tests
========== Discover test finished: 11 found (0:00:00.936) ==========
------ Run test started ------
[xUnit.net 00:00:00.3900232]   Starting:    MyProj.Tests
[xUnit.net 00:00:27.4911173]     View the Daring Fireball archive [FAIL]
[xUnit.net 00:00:27.4958191]       System.NullReferenceException : Object reference not set to an instance of an object.
[xUnit.net 00:00:27.4987971]       Stack Trace:
[xUnit.net 00:00:27.4999882]         C:\git\MyProj.Tests\StepDefinitions\Common\HtmlNavigationSteps.cs(24,0): at MyProj.Tests.StepDefinitions.Common.HtmlNavigationSteps.IGoTo(String text)
[xUnit.net 00:00:27.5010869]            at lambda_method(Closure , IContextManager , String )
[xUnit.net 00:00:27.5022270]            at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
[xUnit.net 00:00:27.5033948]            at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
[xUnit.net 00:00:27.5039611]            at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance)
[xUnit.net 00:00:27.5044492]            at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
[xUnit.net 00:00:27.5048664]            at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
[xUnit.net 00:00:27.5053708]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.ScenarioCleanup()
[xUnit.net 00:00:27.5060798]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.RunScenario(SpecFlowDocument gherkinDocument, Scenario scenario)
[xUnit.net 00:00:27.5068639]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.<>c__DisplayClass9_0.<RunTestAsync>b__2()
[xUnit.net 00:00:27.5082348]       Output:
[xUnit.net 00:00:27.5090068]         Given I am on the https://daringfireball.net/ page
[xUnit.net 00:00:27.5097676]         -> done: PageNavigation.GivenIAmOnThePage("https://daringfir...") (3.5s)
[xUnit.net 00:00:27.5105438]         When I click the link with text Archive
[xUnit.net 00:00:27.5113023]         When I go to https://dev-apdirect.airproducts.com/AgentsPlus/CustomerSearch.aspx
[xUnit.net 00:00:27.5121925]         -> error: Object reference not set to an instance of an object.
[xUnit.net 00:00:27.5129174]         -> done: HtmlNavigationSteps.WhenIClickTheLinkWithText("Archive") (0.0s)
[xUnit.net 00:00:27.5135176]         Then I will arrive on the page titled Daring Fireball: Archive
[xUnit.net 00:00:27.5142561]         -> skipped because of previous errors
[xUnit.net 00:00:27.5296309]   Finished:    MyProj.Tests
========== Run test finished: 1 run (0:00:27.615) ==========

When I call the GivenIGoTo() method directly, without using Given(), I get this:

------ Discover test started ------
NUnit Adapter 3.10.0.21: Test discovery starting
Assembly contains no NUnit 3.0 tests: C:\git\MyProj.Tests\bin\Debug\MyProj.Tests.dll
NUnit Adapter 3.10.0.21: Test discovery complete
[xUnit.net 00:00:00.4054618]   Discovering: MyProj.Tests
[xUnit.net 00:00:00.8653138]   Discovered:  MyProj.Tests
========== Discover test finished: 11 found (0:00:00.949) ==========
------ Run test started ------
[xUnit.net 00:00:00.3959460]   Starting:    MyProj.Tests
[xUnit.net 00:00:27.6141096]     View the Daring Fireball archive [FAIL]
[xUnit.net 00:00:27.6166878]       System.NullReferenceException : Object reference not set to an instance of an object.
[xUnit.net 00:00:27.6184162]       Stack Trace:
[xUnit.net 00:00:27.6190119]         C:\git\MyProj.Tests\StepDefinitions\Common\HtmlNavigationSteps.cs(24,0): at MyProj.Tests.StepDefinitions.Common.HtmlNavigationSteps.IGoTo(String text)
[xUnit.net 00:00:27.6196352]         C:\git\MyProj.Tests\StepDefinitions\Common\HtmlNavigationSteps.cs(18,0): at MyProj.Tests.StepDefinitions.Common.HtmlNavigationSteps.WhenIClickTheLinkWithText(String text)
[xUnit.net 00:00:27.6204164]            at lambda_method(Closure , IContextManager , String )
[xUnit.net 00:00:27.6210895]            at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
[xUnit.net 00:00:27.6217649]            at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
[xUnit.net 00:00:27.6225196]            at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance)
[xUnit.net 00:00:27.6232286]            at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
[xUnit.net 00:00:27.6238029]            at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
[xUnit.net 00:00:27.6244058]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.ScenarioCleanup()
[xUnit.net 00:00:27.6250710]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.RunScenario(SpecFlowDocument gherkinDocument, Scenario scenario)
[xUnit.net 00:00:27.6257423]            at SpecFlow.xUnitAdapter.SpecFlowPlugin.Runners.ScenarioTestCaseRunner.<>c__DisplayClass9_0.<RunTestAsync>b__2()
[xUnit.net 00:00:27.6270580]       Output:
[xUnit.net 00:00:27.6276855]         Given I am on the https://daringfireball.net/ page
[xUnit.net 00:00:27.6282959]         -> done: PageNavigation.GivenIAmOnThePage("https://daringfir...") (3.6s)
[xUnit.net 00:00:27.6289091]         When I click the link with text Archive
[xUnit.net 00:00:27.6295082]         -> error: Object reference not set to an instance of an object.
[xUnit.net 00:00:27.6301183]         Then I will arrive on the page titled Daring Fireball: Archive
[xUnit.net 00:00:27.6308160]         -> skipped because of previous errors
[xUnit.net 00:00:27.6416392]   Finished:    MyProj.Tests
========== Run test finished: 1 run (0:00:27.721) ==========

I also see this at the end of the output pane:

System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion.
Matt W
  • 11,753
  • 25
  • 118
  • 215
  • Do you get a compile error or is this an exception? If it's an exception, could you post the type of exception and message? – Andreas Willich Mar 22 '18 at 14:35
  • That last part of my post is what comes out in the output pane, so not an exception per we. This is during (at the end of) the run, not build time. – Matt W Mar 22 '18 at 14:40

1 Answers1

0

The short answer is that this is very unwise. I'm not entirely sure why the API is allegedly supported by SpecFlow when it is so flaky.

Allegedly:

Don't:

Matt W
  • 11,753
  • 25
  • 118
  • 215