【问题标题】:Specflow calling step from step definition throws TechTalk.SpecFlow.SpecFlowException: Container of the steps class has not been initialized步骤定义中的 Specflow 调用步骤抛出 TechTalk.SpecFlow.SpecFlowException:步骤类的容器尚未初始化
【发布时间】:2017-02-08 19:11:36
【问题描述】:

我试图从步骤定义中调用一个步骤,但是当我这样做时我得到了一个SpecFlowException

看下面的例子:

[Binding]
public class MySteps: Steps 
{
    [Given("Doing some actions, getting (.*)  and (.*)")]
    public void DoingSomeActionsGettingValueAndOtherValue(int a, int b)
    {
        Given($"I pass first integer {a} and second integer {b}");
    }

    [Given(@"I pass first integer (.*) and second integer (.*)")]
    public void ThenIPassFirstIntegerValueAndSecondIntegerValue(int a, int b)
    {
        AreEqual(a, b);
    }
}

例外情况如下:

-> error: Container of the steps class has not been initialized!
TechTalk.SpecFlow.SpecFlowException: Container of the steps class has not been initialized!
   at TechTalk.SpecFlow.Steps.AssertInitialized()
   at TechTalk.SpecFlow.Steps.get_TestRunner()
   at TechTalk.SpecFlow.Steps.Given(String step)

谁能解释我为什么会收到这个特定的错误以及如何解决它?我在文档方面找不到太多帮助。

【问题讨论】:

    标签: c# specflow


    【解决方案1】:

    我试图在一个新项目中重现您的错误,但它成功了。

    我的 specflow 类是从你的复制而来的:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using NUnit.Framework;
    using TechTalk.SpecFlow;
    
    namespace ClassLibrary3
    {
        [Binding]
        public class MySteps : Steps
        {
            [Given("Doing some actions, getting (.*)  and (.*)")]
            public void DoingSomeActionsGettingValueAndOtherValue(int a, int b)
            {
                Given($"I pass first integer {a} and second integer {b}");
            }
    
            [Given(@"I pass first integer (.*) and second integer (.*)")]
            public void ThenIPassFirstIntegerValueAndSecondIntegerValue(int a, int b)
            {
                Assert.AreEqual(a, b);
            }
        }
    }
    

    这是功能文件:

    Feature: SpecFlowFeature1
        In order to avoid silly mistakes
        As a math idiot
        I want to be told the sum of two numbers
    
    @mytag
    Scenario: Add two numbers
        Given Doing some actions, getting 1  and 1
    

    我的建议是尝试在新项目中重现该错误,如果它在那里成功,则该错误一定隐藏在您未在问题中发布的代码中。

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 2014-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      相关资源
      最近更新 更多