从1.0.1将Machine.Fakes更新为1.7之后,我将得到一个"WithFakes尚未初始化。您是从静态初始化器调用它吗?“错误/异常
我把我的考试安排成这样:
[TestFixture]
public class MailSenderTests : WithSubject<MailSender>
{
[TestFixture]
public class TheSendMethod : AssertionHelper
{
[Test]
public void Test_that_exception_is_thrown_if_no_recievers()
{
Expect(() => Subject.Send(string.Empty, string.Empty, recievers: null), Throws.InstanceOf<ArgumentException>());
}
}
}我在SUT中测试的每个方法都有一个类。
有人能告诉我我做错了什么吗?
发布于 2013-09-06 17:02:25
您没有按照预期的方式使用Machine.Fakes。它是Machine.Specifications的扩展,没有它就没有意义。您正在使用代码示例中的其他测试框架。这种不兼容性与版本无关--除了已经引入的显式错误消息之外。
关于shamp00的回答,我想说的是:
using System;
using Machine.Fakes;
using Machine.Specifications;
namespace SOAnswers
{
[Subject(typeof(MailSender), "Sending an Email")]
public class When_no_receivers_are_specified : WithSubject<MailSender>
{
static Exception exception;
Because of = () =>
exception = Catch.Exception(() => Subject.Send(string.Empty, string.Empty, receivers: null));
It should_throw_an_exception = () =>
exception.ShouldBeOfType<ArgumentException>();
}
}我觉得这很有表现力。-)但是,如果您不想使用Machine.Specifications,我想您应该寻找一个更适合的自动锁定框架。
发布于 2013-09-05 15:45:31
嗯,我想自从1.0.1版本以来,已经发生了很大的变化。在1.7.0版本中,您的测试应该如下所示
public class Given_a_MailSender : WithSubject<MailSender>
{
static Exception Exception;
Because of = () =>
{
Exception = Catch.Exception(() => Subject.Send(string.Empty, string.Empty, receivers: null));
};
It should_throw_an_exception = () => Exception.ShouldBeOfType<ArgumentException>();
}https://stackoverflow.com/questions/18632788
复制相似问题