I found that this custom tool is used for generation of .cs files from SpecFlow's .feature file.
Is there a way to use this tool outside of VS?
I would like to call this tool from console for specific .feature file when building my project with NAnt.
Regards,
Vajda Vladimir
You sure can! That is if you mean: "Can I generate unit test code from my .feature-files without using Visual Studio"
I've written about that here: http://www.marcusoft.net/2010/12/specflowexe-and-mstest.html but in short you can use the SpecFlow.exe with the "generateAll" switch, and it will inspect your project settings and generate the appropiate unit tests for you (in my example it's MsTest but it can be any of the supported testing frameworks).
The SpecFlow.exe's help we get the following concise help:
Generate tests from all feature files in a project
usage: specflow generateall projectFile [/force] [/verbose]
projectFile Visual Studio Project File containing features
So for a project called Specs.csproj it would be:
"%ProgramFiles(x86)%\TechTalk\SpecFlow\SpecFlow.exe" generateAll Specs\Specs.csproj /force /verbose
You can read more in my blog post - but this is basically it.
Related
When i create a project and i try to add a feature file, feature file gets created without designer code(i.e a .cs file is not getting created)All the tags "Given ,when, then , Scenario" is not getting recognized.
Which .dll are getting are missed, can somebody help me on this??
You need the SpecFlow NuGet package.
I have gone through the Opencover wiki documentation and tried a lot to figure out what would be the filter criteria for not to include test assembly as part of code coverage. Here is the problem
for eg I have many assemblies starts with sample name like sample.submodule.assembly1.dll, sample.submodule.assembly2.dll, my tests assembly also starts with sample like sample.submodule.tests.dll, here I applied the filter criteria for openCover
1.-filter: "+[sample*]* -[*tests]*"
it didn't work, not generating report file.
-filter: "+[sample*]* -[sample.submodule.tests]*" didn't work, not generating report file,
-filter: "+[sample*]* -[*]*tests*" didn't work, not generating report file too,
can somebody please advise what can be the filter criteria here to exclude all the test files from code coverage
First run OpenCover without any filters.
Now you can look at the XML report produced (or you can use ReportGenerator to turn it into HTML) and identify assemblies/modules that you wish to exclude.
now you can apply filters using the filter switch e.g.
-filter:"+[*]* -[*.tests]* -[*.Tests]*"
NOTE: no space between : and first "
or
"-filter:+[*]* -[*.tests]* -[*.Tests]*"
if you are talking about writing unit test using visual studio nunit adaptor then you have open cover UI visual studio extension available for all such purpose. it is wonderful.
Step 1) Install open cover from latest relese build https://github.com/opencover/opencover/releases
Step 2) Usuall it will install C:\Users\goma1940\AppData\Local\Apps\OpenCover (%localappdata%\Apps\OpenCover)
Steo 3) Install VS Extn from gallery https://visualstudiogallery.msdn.microsoft.com/6950a046-8919-4935-8542-c6f37956f688
Step 4) you have open cover test explorer and open cover coverage result pane as below…
By default, Maven standard directory layout has two Java source folders:
src/main/java
src/test/java
For my purposes, I need a third one src/junit/java which should be packaged into a JAR with the classifier junit.
If possible, the new source folder should have it's own classpath (compile + everything with scope junit).
My guess is that for this, I will have to modify at least the resource and compile plugins.
Or is there an easier way?
I have a workaround as explained here but for that, I have to put things like Mockito and JUnit on the compile classpath which violates my sense of purity.
For all people who doubt the wisdom of my approach: I have support code that help to write unit tests when you work with code from src/main/java. Since I'm using the same support code in the tests for the project itself, this code needs to be compiled after src/main/java and before src/test/java.
Specifically, my support code needs to import code from src/main/java and the tests need to be able to import the support code.
I've seen a couple of Maven setups, which bundle test code in an own Maven module. You could then create a simple main-module <- support-module <- test-module dependency chain with that. But then main-module would compile fine, if you build it on it's own without test-module. Ofc you could aggreate them together with a reactor-pom and just build the project via this pom.
Edit:
If you have problems with this setup regarding code coverage, you can use the Jacoco Maven plugin to aggregate the test coverage generated by test-module to main-module. See this for further information: http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/
In my application project i have used AppDomain.CurrentDomain.BaseDirectory to get the file path. When i include the unit test in my project, the AppDomain.CurrentDomain.BaseDirectory returns unit test project directory instead of my source project while debugg. Can you please let me know how to resolve this issue?
Thanks.
That's the expected behaviour.
You could consider copying the required files to the unit test directory.
In Visual Studio 2010, look at "Deployment" under "Test Settings".
Default setting point to bin\debug folder in Visual studio 2010 test projects. But if you enable deployment option of Edit test settings, AppDomain.CurrentDomain.BaseDirectory points to the TestResults\Out folder. I have added unit test project first, later with additional projects.
Joe, can you provide link from MSDN to support your expected behaviour answer?
I would suggest to read this answer for referring to the location where your assembly resides.
https://stackoverflow.com/a/8670008/2611808
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.