Run Specflow Feature file with Nunit Console from 3.4 and above - c#

I need to run my Speflow feature file with Nunit 3.6 console. Just need to know how can i run specific feature? As fixure is not supported anymore so just need to know what else can be used? Tried --test = but no luck.
I've tried below command line
%windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe "C:\jenkins\workspace\Nunit_ME_Test\Automation\Automation.csproj"
C:\nunit\nunit3.7.0\nunit3-console.exe C:\jenkins\workspace\Nunit_ME_Test\Automation\bin\Debug\Automation.dll --test=ME_NTJ_Include
I have used -test=ME_NTJ_Include where "ME_NTJ_Include" is the feature file .I'm sure something is not right , can any one please help to resolve this .
Thanks

To learn exactly how SpecFlow is naming your tests at different levels, simply run all of them and examine the XML result file. The name you find there for FullName is what you would have to use with the --test option. Most likely, you are simply issing the namespace in which the fixture is defined.
For more flexibility, use the --where option. That would allow you to write, for example --where test=~ME_NTJ_INCLUDE for a partial match of the name.

Related

Specflow filter tests by tag without vstest.console (Xunit.runner)

I feel like this should be incredibly simple but I am using xunit.runner to run my specflow tests. I have added smoke and regression tags. I know I can run via the vstest console and use something like
dotnet test --filter <Smoke>
I can't see an option to filter via the xunit.runner.json can't see anything to suggest where I could filter from. I know SpecRunner allows you to do it
Cheers
After being pointed in the right direction by #Amirreza Hashemi
i created a .runsettings file and added
<RunConfiguration>
<TestCaseFilter>Category=smoke</TestCaseFilter>
</RunConfiguration>

How to use Nunit custom result writer

https://github.com/nunit/docs/wiki/Result-Writers
I'm trying to write customresults for my application using Nunit. But I'm not getting anywhere as I am not able to find any sample on how to implement. Any idea?
[Extension]
[ExtensionProperty("Format", "custom")]
public class CustomResultWriterFactory : IResultWriter
{
...
}
It seems that your question is not really about how to implement a writer (since you have already done that) but how to install it so that NUnit will use it. Is that correct? In any case, that's what I'm answering. :-)
I could be more specific if I knew how you are using NUnit because (unfortunately) there are some differences in what you have to do. I'll assume you run tests using the NUnit console runner, since that's the only way to use the format option. Further, I will assume you installed the console using the nuget package. If you did something else, minor adjustments are needed to the steps you should follow.
Look in the directory where the console runner and engine are installed. It should be in something like packages\NUnit.ConsoleRunner.3.8.0\tools depending on the version you are using.
You should see nunit.engine.dll in that directory as well as a file named nunit.nuget.addins. That .addins file is set up to find any extension packages, which are also installed using nuget. If you had a nuget package for your own extension and installed it, NUnit would find it immediately. Let's assume you do not, however.
In the same directory, create a new text file with file type .addins. You can use any name, so long as it doesn't conflict with any other file in the directory. Edit the file so it contains one line with the absolute or relative path to your extension. For example:
....\my\extensions\CustomReportWriter.dll
Run the console runner with the option --list-extensions. You should see your extension listed.
Run the console specifying --result:path/to/result/file.result.xml;format=custom. You should get your custom output.
NOTE: As you see, I made a lot of assumptions, which could be wrong. That's because you didn't give us a lot of info in your question and I felt this was friendlier than just saying "Write better questions!" But please learn how to write better questions that give all the information needed to help you. :-)

Console Application to launch Specflow features by code not using ncode runner

I have programmed an console application with c# for ranorex automation.
Within the exe i have build i would like to kick off the specflow feature files manually.
I believe I need to create a TestRunnerManager and trigger the run.
Can anyone help?
Although not familiar with nunit, I guess like with mstest, attributes are used to mark methods in an assembly as tests. You could use reflection to find these methods in the assembly and invoke them
This question is similar in spirit to one I asked a while back about MsTest (How do you run SpecFlow scenarios from the command line using MSTest?).
Remember that SpecFlow feature files become C# classes. Scenarios within a feature file become test methods. You can use the nunit-console command line utility to run these:
nunit-console /fixture:Your.Test.Project Your.Test.Project.dll
Which should run all the tests in the Your.Test.Project namespace.
When annotating scenarios using #CategoryName:
#Feature1
Scenario: Some cool feature
Given ...
You should be able to run those from the command line as well:
nunit-console /include:Feature1 Your.Test.Project.dll
Note: This is from an older version of NUnit. Current documentation: https://github.com/nunit/docs/wiki/Console-Command-Line
I use MsTest with Specflow, so my examples might not be correct, but this should put you on the right path. Just look at the *.feature.cs files generated by the .feature file to give you some hints.
No need to create your own console application to run these tests. Worst case scenario, create a batch file or PowerShell script to kick off the tests you want.

Feature file execution with NUnit

I am trying to run a feature file with NUnit Console. I tried googling it and checked NUnit3 help also. But I am unable to find any help.
I want to run either single feature file or any scenario in a feature file which has tag assigned. I am using specflow with specrun. I tried NUnit console command for where "test == path of feature file" but it is not executing test. However I am able to execute all test cases by giving project dll file path. But I just want to execute a single feature file or single scenario in a feature file. Please let me know how can I do this so that I will be able to generate NUnit testresult.xml file.
Thanks.
if you are using SpecRun then you can use the command line of SpecRun to run the tests.
If you really want to use NUnit then you first have to make sure that the project containing the feature files has been compiled. Once you have a test dll this will contain the NUnit tests just like any other and the test categories will be set based on the tags, so you can execute them all by telling NUNit to run tests in the test dll, or you can run tests which have a Tag by telling Nunit to run tests which are in a category matching the Tag.
Running just a feature will be more tricky as there is nothing which groups the scenarios by feature in the tests I don't think, though I may be wrong.
instead of test==featurefile use name==FeatureName

Pass parameters to NUnit test

I'm calling nunit test from Jenkins and I need to be able to specify just one URL address as parameter which I can use inside test. Is there possibility to do that?
For example I'm calling "Execute Windows batch command" in Jenkins like that:
"C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" "D:\selenium\SeleniumTest.dll" /run:SeleniumTest.Test.MyTest
Any ideas?
As far as I currently know of, there is no solution to provide just that what you describe that you want. Best option is to use NUnit project files, modify settings there and pass the solution file to the runner.
On the other hand, you could try to use the Environment variable.
Use set from the command-line. Then read the value using Environment.GetEnvironmentVariable() and use that within your testmethod.

Categories