我试图从步骤定义中调用一步,但是当我这样做时,我会得到一个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)
有人可以解释为什么我会收到此特定错误,我该如何解决?我在文档上找不到太多帮助。
答案 0 :(得分:0)
我试图在新项目中重现您的错误,但它对我来说很成功。
我的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
我的建议是尝试在新项目中重现错误,如果在那里成功,则错误必须隐藏在您未在问题中发布的代码中。