[specflow] Null Reference Exception in TestFixtureSetUp for v1.3

858 views
Skip to first unread message

Brian Hazzard

unread,
May 14, 2010, 3:32:15 PM5/14/10
to SpecFlow
I have a small suite of tests that worked using version 1.2.

I installed v1.3 VS integration and swapped out the
TechTalk.SpecFlow.dll that I reference in my test project for the one
included in the 1.3 download and now they fail with the following
error message:

ProjectName.Behavior.Features.FeatureName (TestFixtureSetUp):
System.NullReferenceException : Object reference not set to an
instance of an object.

at TechTalk.SpecFlow.Bindings.MethodBinding.InvokeAction(Object[]
arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.Bindings.MethodBinding.InvokeAction(Object[]
arguments, ITestTracer testTracer)
at TechTalk.SpecFlow.TestRunner.FireEvents(BindingEvent bindingEvent,
IEnumerable`1 tags)
at TechTalk.SpecFlow.TestRunner.OnTestRunnerStart()
at TechTalk.SpecFlow.TestRunner.InitializeTestRunner(Assembly[]
bindingAssemblies)
at
TechTalk.SpecFlow.ObjectContainer.<>c__DisplayClass1.<EnsureTestRunner>b__0()
at TechTalk.SpecFlow.ObjectContainer.GetOrCreate[TInterface]
(TInterface& storage, Func`1 factory)
at TechTalk.SpecFlow.ObjectContainer.EnsureTestRunner(Assembly
callingAssembly)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner()
at ProjectName.Behavior.Features.FeatureName.FeatureSetup() in C:\Users
\brian.hazzard\Documents\Source\ProjectName.Behavior\Features
\FeatureName.feature.cs:line 0


If I swap it back to the .dll that was included in v1.2 all is well
again.

Any idea what is going on here?

Jonas Bandi

unread,
May 18, 2010, 2:15:11 AM5/18/10
to spec...@googlegroups.com
Could you please try to regenerate the test-fixtures (code-behind) from your feature files.
This can be done in one of the following ways:
- Change the feature file (ie. add a whitespace somewhere) and then save the file.
- In "Properties" of the feature file choose "Run Custom Tool"
- Use the MSBuild task of SpecFlow to regenerate all text-fixtures from feature files in the solution

Please tell me if that solved the issue.
--
mail: jonas...@gmail.com
web: www.jonasbandi.net
blog: blog.jonasbandi.net
twitter: twitter.com/jbandi

Brian Hazzard

unread,
May 18, 2010, 11:00:10 AM5/18/10
to spec...@googlegroups.com
I reapplied the SpecFlow 1.3 dlls and then regenerated the test-fixtures and the same result occurred. To provide some extra background:

I am using NUnit as my test runner. In the same project I have:

    [SetUpFixture]
    public class DatabaseFixture
    {
    }

With all the associated SetUp and TearDown to create a database and it's tables, and then destroy them when all the tests have completed.

With 1.2 this worked correctly and the databases were created and destroyed before and after the suite ran... but with 1.3 it seems to fail in the DatabaseFixture setup. Again, if I revert back to the SpecFlow 1.2 dlls all is well again.

Brian Hazzard

Brian Hazzard

unread,
May 18, 2010, 11:16:15 AM5/18/10
to spec...@googlegroups.com
Another interesting symptom:

When I try to set a breakpoint in the generated test-fixture Visual Studio gives the message "The breakpoint will not currently be hit. No executable code is associated with this line. Possible causes inclide conditional compilation or compiler optimizations."

Yet I can set breakpoints in my Step Definitions and Events, as well as my NUnit fixtures. These breakpoints never get hit though.

Brian Hazzard

Gáspár Nagy

unread,
May 26, 2010, 11:42:06 AM5/26/10
to SpecFlow
Hi,

This later behavior is because of the debugging support we have
introduced. You can switch off the debugging support from the
configuration (<generator allowDebugGeneratedFiles="true" />).

I have no idea why you get the nullref ex. What you can do is to debug
the execution, stop at the exception and see which method SpecFlow is
about to call. Maybe it shows the issue.

On the other hand, SpecFlow has it's own event infrastructure that can
be used for implementing db setup / tear down logic. Maybe the direct
unit-test solution is somehow confusing with SpecFlow. You need to use
the [Before/AfterTestRun] events.

Br,
Gaspar

On May 18, 5:16 pm, Brian Hazzard <bhazz...@gmail.com> wrote:
> Another interesting symptom:
>
> When I try to set a breakpoint in the generated test-fixture Visual Studio
> gives the message "The breakpoint will not currently be hit. No executable
> code is associated with this line. Possible causes inclide conditional
> compilation or compiler optimizations."
>
> Yet I can set breakpoints in my Step Definitions and Events, as well as my
> NUnit fixtures. These breakpoints never get hit though.
>
> Brian Hazzard
>

> On Tue, May 18, 2010 at 11:00 AM, Brian Hazzard <bhazz...@gmail.com> wrote:
> > I reapplied the SpecFlow 1.3 dlls and then regenerated the test-fixtures
> > and the same result occurred. To provide some extra background:
>
> > I am using NUnit as my test runner. In the same project I have:
>
> >     [SetUpFixture]
> >     public class DatabaseFixture
> >     {
> >     }
>
> > With all the associated SetUp and TearDown to create a database and it's
> > tables, and then destroy them when all the tests have completed.
>
> > With 1.2 this worked correctly and the databases were created and destroyed
> > before and after the suite ran... but with 1.3 it seems to fail in the
> > DatabaseFixture setup. Again, if I revert back to the SpecFlow 1.2 dlls all
> > is well again.
>
> > Brian Hazzard
>

> > On Tue, May 18, 2010 at 2:15 AM, Jonas Bandi <jonas.ba...@gmail.com>wrote:
>
> >> Could you please try to regenerate the test-fixtures (code-behind) from
> >> your feature files.
> >> This can be done in one of the following ways:
> >> - Change the feature file (ie. add a whitespace somewhere) and then save
> >> the file.
> >> - In "Properties" of the feature file choose "Run Custom Tool"
> >> - Use the MSBuild task of SpecFlow to regenerate all text-fixtures from
> >> feature files in the solution
>
> >> Please tell me if that solved the issue.
>

> >> mail: jonas.ba...@gmail.com

Brian Prothero

unread,
Jun 10, 2010, 8:33:22 PM6/10/10
to SpecFlow
Has this been resolved? I am still having this issue. Looks like its
throw the exception at
the featuresetup method.

testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();

This is only happens if I have a BeforeTestRunMethod in my class. I
don't have any NUnit setup methods any where.

On May 26, 8:42 am, Gáspár Nagy <gaspar.n...@gmail.com> wrote:
> Hi,
>
> This later behavior is because of the debugging support we have
> introduced. You can switch off the debugging support from the
> configuration (<generator allowDebugGeneratedFiles="true" />).
>
> I have no idea why you get the nullref ex. What you can do is to debug
> the execution, stop at the exception and see which methodSpecFlowis
> about to call. Maybe it shows the issue.
>
> On the other hand,SpecFlowhas it's own event infrastructure that can
> be used for implementing dbsetup/ tear down logic. Maybe the direct
> unit-test solution is somehow confusing withSpecFlow. You need to use
> the [Before/AfterTestRun] events.
>
> Br,
> Gaspar
>
> On May 18, 5:16 pm, Brian Hazzard <bhazz...@gmail.com> wrote:
>
> > Another interesting symptom:
>
> > When I try to set a breakpoint in the generated test-fixture Visual Studio
> > gives the message "The breakpoint will not currently be hit. No executable
> > code is associated with this line. Possible causes inclide conditional
> > compilation or compiler optimizations."
>
> > Yet I can set breakpoints in my Step Definitions and Events, as well as my
> > NUnit fixtures. These breakpoints never get hit though.
>
> > Brian Hazzard
>
> > On Tue, May 18, 2010 at 11:00 AM, Brian Hazzard <bhazz...@gmail.com> wrote:
> > > I reapplied theSpecFlow1.3 dlls and then regenerated the test-fixtures
> > > and the same result occurred. To provide some extra background:
>
> > > I am using NUnit as my test runner. In the same project I have:
>
> > >     [SetUpFixture]
> > >     public class DatabaseFixture
> > >     {
> > >     }
>
> > > With all the associatedSetUpand TearDown to create a database and it's
> > > tables, and then destroy them when all the tests have completed.
>
> > > With 1.2 this worked correctly and the databases were created and destroyed
> > > before and after the suite ran... but with 1.3 it seems to fail in the
> > > DatabaseFixturesetup. Again, if I revert back to theSpecFlow1.2 dlls all
> > > is well again.
>
> > > Brian Hazzard
>
> > > On Tue, May 18, 2010 at 2:15 AM, Jonas Bandi <jonas.ba...@gmail.com>wrote:
>
> > >> Could you please try to regenerate the test-fixtures (code-behind) from
> > >> yourfeaturefiles.
> > >> This can be done in one of the following ways:
> > >> - Change thefeaturefile (ie. add a whitespace somewhere) and then save
> > >> the file.
> > >> - In "Properties" of thefeaturefile choose "Run Custom Tool"
> > >> - Use the MSBuild task ofSpecFlowto regenerate all text-fixtures from
> > >>featurefiles in the solution

Jonas Bandi

unread,
Jun 11, 2010, 1:53:23 AM6/11/10
to spec...@googlegroups.com
Hi Brian,
the Bug is resolved in the current sources on Github (master).
We hope to do a bugfix release next week.

Sorry for the inconvenience.
jonas

--
mail: jonas...@gmail.com

Brian Prothero

unread,
Jun 11, 2010, 11:55:24 PM6/11/10
to spec...@googlegroups.com
Awesome. Thanks!
Reply all
Reply to author
Forward
0 new messages