【发布时间】:2013-01-07 08:33:54
【问题描述】:
在 MSpec 中有一个简洁的功能,允许您在多个测试之间共享断言。他们叫"behaviors"
行为定义了封装一组特定的可重用规范, 你猜对了,行为;然后您就可以将这些规范包含在 任何表现出特定行为的上下文。
您将它们定义为带有断言的类(It 字段)
public class VehicleThatHasBeenStartedBehaviors
{
protected static IVehicle vehicle;
It should_have_a_running_engine = () => vehicle.IsEngineRunning.ShouldBeTrue();
It should_be_idling = () => vehicle.RevCount.ShouldBeBetween(0, 1000);
}
并将它们包含在您的测试类中,例如
public class when_starting_a_car
{
Behaves_like<VehicleThatHasBeenStartedBehaviors> a_started_vehicle;
}
如何使用 NUnit 完成同样的任务?
【问题讨论】:
-
你的意思是两个测试同时运行吗?或者为两个测试运行某种验证?您有使用此功能的代码示例或链接吗?
-
我希望有 1 个类的断言包含在另一个类中。不能使用继承。例子。 lostechies.com/jamesgregory/2010/01/18/behaviours-in-mspec
标签: .net unit-testing nunit mspec