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
Related
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.
Is there a good GUI based test runner for the OCUnit/XCode 4 unit testing frameworks? I'm looking for a redlight/greenlight type GUI, maybe something that looks like the NUnit test runner. I found OCRunner, but it looks like it hasn't been maintained since 2009. It's unfortunate, because OCRunner looks like it was exactly what I was searching for. It loads on Lion, but I can't get it to pick up my test bundle and run it.
Any suggestions for an alternative or a way to get OCRunner to run on a unit test bundle against an iOS project?
*FYI - I'm running XCode 4 with the default unit testing bundle template
You should use GHUnit.
I've also managed it to run it automatically under Jenkins with the iOS Simulator. GHUnit can also export Jenkins valid XML's (JRun).
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.
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.
I'm walking through the FrontStore series tutorial on TDD in MVC (Part 3 by Rob Conery/ASP.NET). The test I'm concerned with is the CatalogRepository_Each_Category_Contains_5_Products(). Until I get to that test, everything was working fine. Now, I've gone through every line that makes this test (including the test itself, the TestCatalogRepository, ...). I've also compared my code to that of Rob, but the test keeps failing.
I also checked the source code from CodePlex, that test was not there.
Now, I wonder if I can put a break point somewhere to check the local values as the test is being executed? If not, something similar?
Thanks for helping.
Debugging tests should be exactly the same as debugging your code - put a break point and run the test in debug (in MSTest ctrl+R, ctrl+T).
Depending on you testrunner (Nunit or VS) you start the test in debug mode (VS) or you start the testrunner and attach to the proces of the testrunner (nunit)
Another approach would be to create unit tests that act as breakpoints. It would require refactoring the SUT.