SpecFlow - Null reference exception - specflow

I've been playing with SpecFlow recently, but I failed to make it work properly. Steps I took are:
1. Downloaded and installed SpecFlow
2. Downloaded and launched Guestbook solution (VS2010)
3. Run NavigationToHomepage test from this project using Visual NUnit under debugger.
4. Got Null Reference Exception on Scenario: Navigation to homepage line.
StackTrace:
in Guestbook.Spec.Features.BrowsingFeature.ScenarioSetup(ScenarioInfo scenarioInfo) in F:\VS Projects\SteveSanderson-GuestbookDemo-bf2bdab\SteveSanderson-GuestbookDemo-bf2bdab\Guestbook.Spec\Features\Browsing.feature.cs:line 0
in Guestbook.Spec.Features.BrowsingFeature.NavigationToHomepage() in f:\VS Projects\SteveSanderson-GuestbookDemo-bf2bdab\SteveSanderson-GuestbookDemo-bf2bdab\Guestbook.Spec\Features\Browsing.feature:line 6
What might be wrong?
UPDATED
I tried to perform the same actions on the another computer and everything worked fine there. I'm completely confused.

I think the best thing to do is create your own:
Create a new solution with a class project.
Add a reference to the TechTalk.SpecFlow dll.
Create a new SpecFlow Feature File.
This will give you a basic spec feature for a calculator.
Compile the app and run it in Nunit test runner.
You'll be given a load of 'no matching step..' errors.
Create a new SpecFlow Step Definition file.
Copy the methods that Nunit test runner gave you into the definition file.
Recompile and run it in Nunit.
Then you just need to implement the guts of each method.
I'm loving SpecFlow for making me write smarter, more manageable code.

Related

Is it possible to execute a SpecFlow test run programmatically?

I would like to invoke SpecFlow tests programmatically. At runtime, I would like to start SpecRunner at some point in time, and execute the tests under the same (current) AppDomain.
Is there a class under TechTalk.SpecRun that can help me?
I have tried using TestRunnerManager.GetTestRunner() but this class does not seem to actually kick off the tests.
EDIT: I am using SpecFlow 3, .NET 4.5.2

What do I need to start using specflow

I'm trying to use SpecFlow for a .net project. I'm new to SpecFlow. The Development team are using NUnit, so it would seem that SpecFlow would be a good option in conjunction with Cucumber. However, the Development team have come back say that SpecFlow cannot be used saying they do not have an API/Service that is available to use at the level required. Currently all of their automated tests are through the UI using Test Complete, I am keen to move to API level testing.
Can anyone explain to me why SpecFlow cannot be used, I'm sorry it's a newbie question but no one can answer it, I've asked everyone I can think of, surely the first steps would be to see if we can use SpecFlow with NUnit but perhaps not.
Can anyone give me a guide on my next steps, how can I be sure this isn't an option without righting it off without concern that it's just being blocked?
Thank you
SpecFlow has a unit test generator that generates unit test code for a variety of unit test frameworks. SpecFlow generates NUnit tests in its default configuration. The getting started page on specflow.org explains a quick way to get up and running with SpecFlow and NUnit, http://www.specflow.org/getting-started/.
If the UI is HTTP based, SpecFlow can be used with WebDriver or another browser automation framework to test the UI. This blog post provides an overview of how to get started with SpecFlow, NUnit and WebDriver, http://blogs.lessthandot.com/index.php/enterprisedev/application-lifecycle-management/using-specflow-to/
I am unclear on the API you want to test. If you could provide more information on the specific API and UI you are trying to test, I could possibly provide some code examples or references for you.
Is the API exposed through HTTP?
Is the UI a web, mobile, or desktop
application?
Have you tried to use SpecFlow at all?
SpecFlow doesn't run tests. It simply maps readable language to tests. If their test can be written as a nunit test, then SpecFlow is available to you to use. With no change, here is how it would look.
Scenario: Running 'testname'
Then I execute the test 'TestName'
You would map that to
[Then(#"I execute the test '(.*)'")]
public void ExecuteSpecificTest(string testname)
{
// Using reflection, execute the method listed
}
Obviously you would want to do better than that. You want a given, when, then so you clearly show the setup, action, and then compare expected verses actual result but it isn't necessary. Best practices however is another discussion.
To sum it up, code is code and SpecFlow simply maps to code. You can use WatiN, WebDriver, or anything else to hook into the UI or an API. SpecFlow doesn't care. It simple executes the methods without knowing what's inside.

Migrating big grails project to Intellij

I am taking over development of a rather large grails project. The development was initially done in STS however I would like to move to IntelliJ Idea.
Initially I thought this would be a piece-of-cake because of the "integrate-with --intellij" command. This is however not the story :(
The project consist of mulitple grails-plugin projects (Please don't ask me why it was developed this way) and some of them with web-descriptors. I start out by migrating one of these, since this is one of the "main" projects (X).
Each of the developed plugins that X has as a dependecy to Intellij creates as "YinplacePlugin" modules where Y is the plugin name. And this is where the fun begins! The "YinplacePlugin" module created for the Y project has of course a lot dependencies it self. These are, if I look in STS, referred to in $USERHOME$/.grails/project/Y/plugins/xxxx and this path is in STS included in the build-path.
But these depencies FAIL in idea. I CAN use the "grails compile" option from within the project however IntelliJ "Make Project" or "Make Module" fails because of missing references. See below:
The first image shows the failing reference. The second how STS has this on the build path.
So why don't you just add the libraries to the build path? one might ask. Well, I tried. One result:
IDEA hook: Grails not found!
| Error java.lang.NullPointerException
| Error at org.jetbrains.groovy.grails.rt.Agent$2.run(Agent.java:99)
| Error at java.lang.Thread.run(Thread.java:662)
I am out of ideas. Any ideas how to get this to build using "Idea Make Project"? All I want is an IDE without "red-lines" so development will be smooth!

Could not find file or assembly when generating specflow tests

I've been happily developing SpecFlow tests on this machine for a while now. Today when I changed some tests and tried to regenerate them I keep getting
Custom tool error: Could not load file or assembly 'TechTalk.SpecFlow, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0778194805d6db41' or one of its dependencies.
I have SpecFlow 1.8.1 installed on my computer and am pulling in the SpecFlow package from NuGet. I've tried reinstalling both of these components with no luck.
Any suggestions as to why this might be happening or where I should go to find more information would be much appreciated.
You need to add reference to the SpecFlow dll into your project AND set its "Copy Local" property to TRUE. Then it should work.
However, if you are trying to run the ms test from TFS, then you may still get this error. (I'm still trying to find out how to fix that.) But at least the above should fix your immediate problem.

Can I get SpecFlow to generate a list of missing step definitions without running the tests?

I'm in the process of refactoring our SpecFlow-implemented BDD tests. As part of this work, I've commented out most of the step definitions.
As I run the tests, I'm presented with the "No matching step definition found for one or more steps." message.
However, I'd prefer not to wait until the tests are actually run. Is there a way to get SpecFlow to check for missing step definitions without running the tests?
You can use the stepdefinitionreport parameter to SpecFlow.exe, as follows:
specflow.exe stepdefinitionreport MyTests.csproj
But be aware:
If your assembly uses the .NET 4.0 runtime, you'll need to add a specflow.exe.config file with a <supportedRuntime> element.
It uses some functionality that's 32-bit only. So if you're on 64-bit Windows, you'll need to use CORFLAGS /32BIT+ to edit the Specflow.exe file.
By default, it looks in the bin\Debug folder.

Resources