我正试图在xBehave和NSpec之间做出决定。关于NSpec,我喜欢的一点是,如果使用特定的语法,可以将测试名称指定为带有空格的字符串:
context["when no subscriptions exist"] = () => { ... }这很好,因为我会输入很多这样的,它们将是句子长度,所以CamelCase或下划线将是一个相对的痛苦。
有人知道在xBehave.net中做类似事情的方法吗?
发布于 2014-10-29 09:13:44
我刚刚开始使用xBehave.net,但是一个典型的测试应该是这样的。
public class CalculatorFeature
{
[Scenario]
public void Addition(int x, int y, Calculator calculator, int answer)
{
"Given the number 1"
.Given(() => x = 1);
"And the number 2"
.And(() => y = 2);
"And a calculator"
.And(() => calculator = new Calculator());
"When I add the numbers together"
.When(() => answer = calculator.Add(x, y));
"Then the answer is 3"
.Then(() => Assert.Equal(3, answer));
}
}此示例取自快速启动部分(https://github.com/xbehave/xbehave.net/wiki/Quickstart)。所以你可以用自然语言写你所有的给定,然后,或者任何你喜欢的东西。我个人使用了一个“创建,什么时候,它应该”的方法,并在周围使用_()扩展方法。
用我的方法进行的测试应该是这样的
public class ListStorySpecifications
{
[Scenario]
public void ListStories(Backlog backlog)
{
IReadOnlyCollection<string> stories = null;
"establish an empty backlog"._(() =>
{
backlog = new Backlog();
});
"when listing all stories"._(() =>
{
stories = backlog.GetAll();
});
"it should return an empty list"._(() =>
stories.Should().BeEmpty());
}
}https://stackoverflow.com/questions/25252887
复制相似问题