0
votes

For starters: I am new to Visual Studio and SpecFlow in general.

Following the getting started documentation on SpecFlow I get 2 different outcomes depending on what type of project I start.

Unit Test Project: in this type of projects, the test's aren't recognized by the runner at all. Only the "SpecRun Evaluation" test runs.

MSTest Test Project (.NET Core): in this type of projects, the tests are always passing but I do get an error in the Tests output: "Value cannot be null. Parameter name: message" and that's caused by a "generator"

I'm doing all this on a typical Windows 10 Pro. I have tried both on VS 2017 and 2019. I have tried re-doing the whole process in case I've missed something. Also tried updating packages. Something that maybe should be noted, Unit Test Projects do not generate an App.config file.

using System;
using TechTalk.SpecFlow;

namespace Tests.Steps
{
    [Binding]
    public class CalculatorSteps
    {
        [Given(@"I have entered (.*) into the calculator")]
        public void GivenIHaveEnteredIntoTheCalculator(int p0)
        {
            Console.WriteLine(p0);
        }

        [Given(@"I have also entered (.*) into the calculator")]
        public void GivenIHaveAlsoEnteredIntoTheCalculator(int p0)
        {
            Console.WriteLine(p0);
        }

        [When(@"I press add")]
        public void WhenIPressAdd()
        {
            Console.WriteLine("add pressed");
        }


        [Then(@"the result should be (.*) on the screen")]
        public void ThenTheResultShouldBeOnTheScreen(int p0)
        {
            Console.WriteLine(p0);
        }

    }
}

I would pretty much expect for the tests to run and to get some kind of a feedback when I intentionally throw an exception in a test.

All of this is just a task for a job application, but what I've provided is the default feature file that gets generated, as both situations have that outcome. I already have an idea how to complete the task and here I am stuck on the Set Up for hours... I really hope it's just my stupidity/inexperience.

.csproj: https://codeshare.io/5zxk0W

1
You mention .NET Core, so I assume you use version 3 of Specflow. You use a json file for configuration in that version, not app.config. Try to set up Specflow according to this page.Mika Sundland
@MikaS Thanks, it seems that doesn't make a difference though, unless I do need to configure a json, because it does say it's not something required. Tests are still not recognized except for the "SpecRun Evaluation". I still need to try on another project, hopefully that'll workMartin Rashev

1 Answers

3
votes

This answer is for SpecFlow 2.*. With SpecFlow 3 you only need to add the SpecFlow.Tools.MSBuild.Generation NuGet package to your project.

You missed one step to enable the MSBuild integration.

You have to put following code at the end of csproj in the tag.

<Target Name="AfterUpdateFeatureFilesInProject">
    <ItemGroup>
    <Compile Include="**\*.feature.cs" Exclude="@(Compile)" />
    </ItemGroup>
</Target>

It is described in https://specflow.org/2019/generating-code-behind-files-using-msbuild/ - Enabling MSBuild Code Behind Generation Classic Project System - Step 2