c# - 获取[当前执行的线程不在步骤定义上下文中]错误
问题描述
我的 ASP.NET Core 3 API 的 BDD 样式单元测试出错。引用的包 (xunit:2.4.1, xbehave:2.4.1,xunit.runner.visualstudio:2.4.2)。
这是导致相同错误的简化示例测试:
[Fact]
public void Test1()
{
int x=0,
y=0,
sum = 0;
"Given x = 20".x(() => x = 20);
"And y = 10".x(() => y = 10);
"When adding x & y".x(() => sum = x + y);
"Then 30 is returned".x(() => Assert.Equal(30, sum));
}
并运行测试抛出异常:
Message: System.InvalidOperationException : The currently executing thread is not in a step definition context. Stack Trace: CurrentThread.Add(IStepDefinition item) StringExtensions.x(String text, Action body) UnitTest1.Test1() line 15
解决方案
适用于旧版本:(xunit:2.4.0, xbehave:2.4.0)
但不适用于最新版本:(xunit:2.4.1, xbehave:2.4.1)
版本:xunit.runner.visualstudio 无关紧要。它适用于(2.4.0 或 2.4.2)。
希望这可以帮助某人。
推荐阅读
- javascript - React - 如何获取我点击的按钮元素?
- cypress - 让赛普拉斯听随机的 DOM 变化?
- dialogflow-es - 如何覆盖 Dialogflow 中的取消字词?
- typescript - 如何在 Typescript 中以不同的名称重新导出枚举?
- reactjs - react-native 数组映射不迭代
- vue.js - 无法使用 npm 链接访问 Vue 指令
- c# - 为什么我的命名空间引用在 Visual Studio 中不断中断?
- excel - 计算唯一值并在另一列中返回结果
- inno-setup - 根据 Innosetup 中的操作系统位数有条件地将任务显示为复选框而不是单选
- sql - SQL:如何将多个视图合并为一个视图?