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

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.

Related

Dealing with shared helpers in Common Test suites?

I've got an Erlang project comprising a bunch of different applications. I'm using Common Test to do some of the testing.
apps/foo/suites/foo_SUITE.erl
apps/bar/suites/bar_SUITE.erl
I'm starting to see duplication of utility code in those suites.
Where should I put my utility code so that it can be shared between the two suites?
I've considered adding another application:
apps/test_stuff
...but I can't make the CT suites depend on this without making the application under test depend on this (or can I?). I don't want to do that, because test_stuff is only needed when testing.
I have a similar problem with my eunit tests, both between applications (apps/foo/test vs. apps/bar/test), and where I'm using similar functionality between the eunit and CT tests in the same application (apps/bar/suites vs apps/bar/test). Can I use the same solution for this case as well? Or do I need to ask another question about that?
Do you think ct:require/1,2 could help you so that foo and bar SUITE would require test_stuff before it gets executed? For more information http://www.erlang.org/doc/man/ct.html#require-1
It depends on how you are packaging your final releases. For example, I use rebar for relase management. I have Cowboy fetched along with other dependencies for testing purposes, but in my reltool.config, I omit it, so it doesn't get packaged with the final product. I use rebar to run Common Test, and it's able to add Cowboy to the path without having it bundled as a lib with everything else or added as a dependency to the app I'm testing.
However, if you have another process which infers your release configuration from your dependencies, you'll have to find a way to exclude your test code when you generate a release.

How to deal with tangled uses dependencies in order to start unit testing?

I have a messy Delphi 7 legacy system to maintain and develop. I am already reading "Working effectively with legacy code" and I like this book very much.
In order to start following the advices in the book, I created a test project and tried to write a single test. To do this I need to add some unit to the test project, but here lies the problem: the system under test has horrific uses dependencies. One unit uses some other unit, that uses some other unit and so on, and so on. It seems that most units directly or indirectly use one particular unit, and this unit in turn has 170 dependencies in its uses clause. There are indirect circular dependencies also.
Currently I am trying to add all of the legacy system's units into the test project, but I am running into all kind of problems, like "unit xxx was compiled with a different version of xxx", and others.
So I wonder if I am doing something wrong. I have used unit testing before, but in my own projects, that were smaller and with better structure and modularization. What are the options I have in this situation? Am I missing something?
You will always have dependencies in your code. Well, as long as you have code re-use, you will have dependencies. Since you are testing a legacy system, wholesale re-structuring is out of the question.
So you simply need to accept the dependencies. The most convenient and practical approach is to have a single unit tests project. That project contains all your unit tests. Use the facilities of your runner program to run only specific tests at any one time.
This leads to your project have the same list of units in its .dpr file as the main project. That's what you have currently tried and it's the right approach.
Your problem sounds like you are sharing the DCU directory (unit output directory) between the main project and the unit tests project. And you have different compiler options for the two projects. That's the most likely explanation for the error you report.
There are a couple of obvious solutions:
Align the compiler options for both projects. Then they can share DCUs.
Have separate DCU directories for the two projects.
Option 2 is much more robust and is best practise. However, you should try to understand why the compiler options differ. It's quite possible that your compiler options in the new unit tests project will need to be changed so that the units under test compile and function as desired. In modern Delphi I would use option sets to ensure consistency of compiler options.
Now, there may be other technical problems that you are facing, and my explanation of the error may not be quite right since I'm having to guess a little. But the bottom line is that having the same list of units in your .dpr files is the way to go.

SpecFlow - Null reference exception

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.

How to force prebuild script to run at each compile

We currently use Delphi 2009 and GIT to develop an application. We have set up a prebuild script to generate a version number and build ID using information from git and compile this as a resource that is included in the project. The problem is that this script doesn't run on a regular compile. This means that the other developers can end up with a discrepancy between the actual version number and the number in the resource (especially when switching branches in git).
Since we use our software to make some critical calculations, we would like to use this build id to reproduce calculations and track down problems.
Other than trying to force my developers to frequently press shift-F9, how can I ensure that the the prebuild script gets run when necessary (ideally at each compile)?
Jason
UPDATE: It's true that the pre-build script gets run at each compile. The problem was that I expected to get a different result pressing F9 after making a tag in git, even though no code had changed.
We solved a similar issue by writing a custom IDE plugin which uses the IOTAIDENotifier50 interface. Specifically using the BeforeCompile method, to test some required project settings and also generate dynamic version information (VERSIONINFO resource). It gets called for every type of build (compile and build). We also generate a unique exe serial number and log everything, which helps us track down issues and is similar to your script. For completeness we have only done this in Delphi 2007 and Delphi XE.
Pre build actions do run before every compile.
You state in a comment that the actions sometimes don't run when you press F9. That makes sense because F9, or Run, only invokes a compile if source is deemed to have changed.
A BeforeCompile notifier plug in will behave in exactly the same way. Your solution is to make sure that you compile before running using Ctrl+F9.

NCover 1.5.8 / NCoverExplorer 1.4.0.7 manual exclusions are very flaky

I haven't yet installed my license of NCover 3, and am still running 1.5.8 on my build server. I am trying to exclude full assemblies and specific classes that I don't want included in the report, because they are artificially lowering the coverage results.
In NCoverExplorer, I was playing around with the options because there is a coverage exclusions section in the Options tab where you can specify full namespaces. I've entered the fully qualified classes, and for some reason, only a handful of them get excluded, and I cannot figure out why. For example, when I add System.ComponentModel.Composition to the list, it never gets excluded!
Is this just a bug in 1.5.8 that I have to live with for now, since it is a beta and also no longer supported? Although I do have a new license for the server, I'd like to be able to do some coverage at home on my personal computer.
I found a really great article on using a CoverageExcludeAttribute to make NCover automatically skip those classes / methods that are marked with this attribute. Is this the best option?
Did you try using regular expressions to include/exclude the assemblies -
//ias AuctionSniper([.\w]*?)(?<!Tests)
includes all assemblies that begin with AuctionSniper but don't end with Tests e.g. AuctionSniper.Main.exe
You can specify multiple patterns separated by semicolons.
or //ias .*vendorsupplied.*;.*tests
This works with NCover 3 - you can give it a try if it works for the free/community edition.
One way to get part way there is to also use the "assemblies to include in coverage" option. This allowed me to ignore System.ComponentModel.Composition. However, exlcuding most of the other classes and namespaces still doesn't work. It's a little odd how when I exclude an entire class, it only excludes the methods, but not any of the contained classes.

Resources