1
votes

I want to be able to change my feature file from outside visual studio and have the updated feature file picked up, for subsequent test execution, without compilation of my test project. Is it possible to do this? Can someone help to specify the exact steps needed to do this? I am using MsTest.

Here are the steps I followed, but I get the message "No tests to execute." every time:

  1. Change Test Project file (.csproj) as mentioned here
  2. Build the Test DLL from Visual Studio
  3. Kept the feature file in a folder FeatureFiles, under the Test release folder
  4. Changed the feature file in Notepad
  5. Used the Specflow generate all command, to regenerate the tests:

    Specflow generateall TestProject.csproj /force /verbose

  6. Create the report:

    mstest /testcontainer:Test.Dll /resultsfile:TestResult.trx

A similar question was asked earlier, and I am following the same steps as mentioned by Marcus there.

Update Here is what I would like to do. Considering the following .feature file:

Feature: Score Calculation

As a player I want the system to calculate my total score So that I know my performance

Scenario: Another beginners game Given a new bowling game When I roll the following series: 2,7,3,4,1,1,5,1,1,1,1,1,1,1,1,1,1,1,5,1 Then my total score should be 40

In the above feature file, I would like to change the data series of numbers and change the total score and run the same test again to check if it runs fine and I get a correct score

2
If you look at the linked question it has since been updated with some extra info which may be useful for youSam Holder

2 Answers

0
votes

I can't see how what you want is possible. SpecFlow generates unit test classes from the feature file. These unit test classes MUST be compiled before they can be run, the same as ANY code change.

You are getting a 'no tests to execute' because you are still running against the old version of the dll, which doesn't contain any tests because you have not rebuilt it with the new code that specflow has generated.

From what is stated in the linked question it seems they are saying that some changes may be able to be run without recompiling, but honestly I cannot see how that is possible, and even if some feature file changes were possible I imagine that the solution would be specific to certain unit test frameworks and unsupported.

EDIT

When I look at the generated feature.cs file you have this:

    [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
    [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Another beginners game")]
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "Score Calculation")]
    public virtual void AnotherBeginnersGame()
    {
        TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Another beginners game", ((string[])(null)));
        #line 5
        this.ScenarioSetup(scenarioInfo);
        #line 6
        testRunner.Given("a new bowling game", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
        #line 7
        testRunner.When("I roll the following series: 2,7,3,4,1,1,5,1,1,1,1,1,1,1,1,1,1,1,5,1", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
        #line 8
        testRunner.Then("my total score should be 40", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
        #line hidden
        this.ScenarioCleanup();
    }

As you can see this contains your actual list of values and expected result in the code

This surely implies that you can't change the feature file and have the test update without recompiling, as otherwise any changes to the cs file will not be reflected in the actual dll that you are running.

0
votes

If you only want to change the data for a test, then go with a CSV file that you save inside your VS project. Then in a Given statement open that file, parse it and save it to the ScenarioContext.Current object for use in subsequent steps.