我正在尝试使用Nspec。 我遵循了以下说明:http://nspec.org/
- 创建类库项目
- Nuget:安装包 nspec
- Nuget:安装包流畅断言
- 创建一个类文件并粘贴以下代码:
using NSpec;
using FluentAssertions;
class my_first_spec : nspec
{
string name;
void before_each()
{
name = "NSpec";
}
void it_asserts_at_the_method_level()
{
name.ShouldBeEquivalentTo("NSpec");
}
void describe_nesting()
{
before = () => name += " Add Some Other Stuff";
it["asserts in a method"] = () =>
{
name.ShouldBeEquivalentTo("NSpec Add Some Other Stuff");
};
context["more nesting"] = () =>
{
before = () => name += ", And Even More";
it["also asserts in a lambda"] = () =>
{
name.ShouldBeEquivalentTo("NSpec Add Some Other Stuff, And Even More");
};
};
}
}
编辑器识别命名空间和 nspec 类,但是我看到一个编译器错误,上面写着:
'string 不包含 ShouldBeEquivalentTo 的定义。
问题出在哪里?
我正在使用.NET 4.7.1和Visual Studio 2017。
我花了一些时间在谷歌上搜索这个,例如我看了这里:https://github.com/fluentassertions/fluentassertions/issues/234
FluentAssertions 已删除ShouldBeEquivalentTo
扩展作为最新版本中的重大更改。
请参阅最近的 FluentAssertions 文档以获取建议的替代方案
https://fluentassertions.com/introduction
name.Should().BeEquivalentTo(...);
您的示例代码需要更新为
class my_first_spec : nspec {
string name;
void before_each() {
name = "NSpec";
}
void it_asserts_at_the_method_level() {
name.Should().BeEquivalentTo("NSpec");
}
void describe_nesting() {
before = () => name += " Add Some Other Stuff";
it["asserts in a method"] = () => {
name.Should().BeEquivalentTo("NSpec Add Some Other Stuff");
};
context["more nesting"] = () => {
before = () => name += ", And Even More";
it["also asserts in a lambda"] = () => {
name.Should().BeEquivalentTo("NSpec Add Some Other Stuff, And Even More");
};
};
}
}