Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Backgrounds cause External Data Plugin to fail #271

Closed
clrudolphi opened this issue Sep 30, 2024 · 0 comments
Closed

Rule Backgrounds cause External Data Plugin to fail #271

clrudolphi opened this issue Sep 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@clrudolphi
Copy link
Contributor

Reqnroll Version

2.1

Which test runner are you using?

NUnit

Test Runner Version Number

3.14

.NET Implementation

.NET 8.0

Test Execution Method

Visual Studio Test Explorer

Content of reqnroll.json configuration file

none

Issue Description

When using the External Data Plugin, if the Scenario Outline that leverages the ExternalDataPlugin is contained within a Rule that happens to have a Background, the generation of code for that feature will not be correct.

The root cause is that the Feature AST visitor used by the External Data Plugin improperly handles Rule Backgrounds. I have a fix to submit against this issue.

Steps to Reproduce

Within a Reqnroll feature, have a feature such as this:

Feature: Calculator

Simple calculator for adding two numbers
Rule: Can also use Rule Backgrounds
	Background: 
	Given the password is KEVIN
@DataSource:externaldata.csv
Scenario Outline: by using a table for inputs and outputs
	Given the first number is <first>
	And the second number is <second>
	When the two numbers are added
	Then the result should be <sum>
	And the password should be KEVIN
	Examples: 
	| first | second | sum |
	| 50    | 70     | 120 |

along with an appropriately matched set of Step Definitions. (see sample repo linked below)
The generated code is:

// ------------------------------------------------------------------------------
//  <auto-generated>
//      This code was generated by Reqnroll (https://www.reqnroll.net/).
//      Reqnroll Version:2.0.0.0
//      Reqnroll Generator Version:2.0.0.0
// 
//      Changes to this file may cause incorrect behavior and will be lost if
//      the code is regenerated.
//  </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
#pragma warning disable
namespace ReqnrollProject1.Features
{
    using Reqnroll;
    using System;
    using System.Linq;
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Reqnroll", "2.0.0.0")]
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [NUnit.Framework.TestFixtureAttribute()]
    [NUnit.Framework.DescriptionAttribute("Calculator")]
    public partial class CalculatorFeature
    {
        
        private global::Reqnroll.ITestRunner testRunner;
        
        private static string[] featureTags = ((string[])(null));
        
#line 1 "Calculator.feature"
#line hidden
        
        [NUnit.Framework.OneTimeSetUpAttribute()]
        public virtual async System.Threading.Tasks.Task FeatureSetupAsync()
        {
            testRunner = global::Reqnroll.TestRunnerManager.GetTestRunnerForAssembly();
            global::Reqnroll.FeatureInfo featureInfo = new global::Reqnroll.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Features", "Calculator", "Simple calculator for adding two numbers", global::Reqnroll.ProgrammingLanguage.CSharp, featureTags);
            await testRunner.OnFeatureStartAsync(featureInfo);
        }
        
        [NUnit.Framework.OneTimeTearDownAttribute()]
        public virtual async System.Threading.Tasks.Task FeatureTearDownAsync()
        {
            await testRunner.OnFeatureEndAsync();
            global::Reqnroll.TestRunnerManager.ReleaseTestRunner(testRunner);
            testRunner = null;
        }
        
        [NUnit.Framework.SetUpAttribute()]
        public async System.Threading.Tasks.Task TestInitializeAsync()
        {
        }
        
        [NUnit.Framework.TearDownAttribute()]
        public async System.Threading.Tasks.Task TestTearDownAsync()
        {
            await testRunner.OnScenarioEndAsync();
        }
        
        public void ScenarioInitialize(global::Reqnroll.ScenarioInfo scenarioInfo)
        {
            testRunner.OnScenarioInitialize(scenarioInfo);
            testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs<NUnit.Framework.TestContext>(NUnit.Framework.TestContext.CurrentContext);
        }
        
        public async System.Threading.Tasks.Task ScenarioStartAsync()
        {
            await testRunner.OnScenarioStartAsync();
        }
        
        public async System.Threading.Tasks.Task ScenarioCleanupAsync()
        {
            await testRunner.CollectScenarioErrorsAsync();
        }
        
        [NUnit.Framework.TestAttribute()]
        [NUnit.Framework.DescriptionAttribute("by using a table for inputs and outputs")]
        [NUnit.Framework.CategoryAttribute("DataSource:externaldata.csv")]
        [NUnit.Framework.TestCaseAttribute("50", "70", "120", null)]
        [NUnit.Framework.TestCaseAttribute("15", "35", "50", null)]
        [NUnit.Framework.TestCaseAttribute("80", "40", "120", null)]
        public async System.Threading.Tasks.Task ByUsingATableForInputsAndOutputs(string first, string second, string sum, string[] exampleTags)
        {
            string[] @__tags = new string[] {
                    "DataSource:externaldata.csv"};
            if ((exampleTags != null))
            {
                @__tags = System.Linq.Enumerable.ToArray(System.Linq.Enumerable.Concat(@__tags, exampleTags));
            }
            string[] tagsOfScenario = @__tags;
            System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary();
            argumentsOfScenario.Add("first", first);
            argumentsOfScenario.Add("second", second);
            argumentsOfScenario.Add("sum", sum);
            global::Reqnroll.ScenarioInfo scenarioInfo = new global::Reqnroll.ScenarioInfo("by using a table for inputs and outputs", null, tagsOfScenario, argumentsOfScenario, featureTags);
#line 8
this.ScenarioInitialize(scenarioInfo);
#line hidden
            if ((global::Reqnroll.TagHelper.ContainsIgnoreTag(scenarioInfo.CombinedTags) || global::Reqnroll.TagHelper.ContainsIgnoreTag(featureTags)))
            {
                testRunner.SkipScenario();
            }
            else
            {
                await this.ScenarioStartAsync();
#line 9
 await testRunner.GivenAsync(string.Format("the first number is {0}", first), ((string)(null)), ((global::Reqnroll.Table)(null)), "Given ");
#line hidden
#line 10
 await testRunner.AndAsync(string.Format("the second number is {0}", second), ((string)(null)), ((global::Reqnroll.Table)(null)), "And ");
#line hidden
#line 11
 await testRunner.WhenAsync("the two numbers are added", ((string)(null)), ((global::Reqnroll.Table)(null)), "When ");
#line hidden
#line 12
 await testRunner.ThenAsync(string.Format("the result should be {0}", sum), ((string)(null)), ((global::Reqnroll.Table)(null)), "Then ");
#line hidden
#line 13
 await testRunner.AndAsync("the password should be KEVIN", ((string)(null)), ((global::Reqnroll.Table)(null)), "And ");
#line hidden
            }
            await this.ScenarioCleanupAsync();
        }
    }
}
#pragma warning restore
#endregion

Note that there is no generated invocation of testRunner.Given for the Rule Background step.

Link to Repro Project

https://github.com/clrudolphi/DemonstrationOfReqnrollExternalDataPluginIssueWithRuleBackground

@clrudolphi clrudolphi added the bug Something isn't working label Sep 30, 2024
clrudolphi added a commit that referenced this issue Sep 30, 2024
gasparnagy pushed a commit that referenced this issue Oct 1, 2024
gasparnagy added a commit that referenced this issue Oct 14, 2024
* main:
  Bump version
  VS Code integration  proper doc title (#280)
  Fix: Reqnroll generates invalid code for rule backgrounds in Visual Basic (#284)
  Update nunit.md (#276)
  SolutionTests: Check if SDK version is installed and if not ignore the test (#266)
  Fix for #271 This PR modifies the Feature AST visitor to appropriately handle Rule Background steps. (#272)
  Bugfix/fix reqnroll.verify parallelization (#255)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant