这是一个老问题,但如果有人还在寻找这个,你应该试试Matt Honeycutt 的 SpecsFor.Mvc。
它不仅可以用来确保Views
正确包含/添加到源代码控制中,它甚至可以进行集成测试以确保它们Views
有效。
链接到其网站:http ://specsfor.com/SpecsForMvc/default.cshtml
nuget 包的链接:https ://www.nuget.org/packages/SpecsFor.Mvc/
github链接:https ://github.com/MattHoneycutt/SpecsFor
这是从网站上截取的代码片段,展示了如何使用它。
public class UserRegistrationSpecs
{
public class when_a_new_user_registers : SpecsFor<MvcWebApp>
{
protected override void Given()
{
SUT.NavigateTo<AccountController>(c => c.Register());
}
protected override void When()
{
SUT.FindFormFor<RegisterModel>()
.Field(m => m.Email).SetValueTo("test@user.com")
.Field(m => m.UserName).SetValueTo("Test User")
.Field(m => m.Password).SetValueTo("P@ssword!")
.Field(m => m.ConfirmPassword).SetValueTo("P@ssword!")
.Submit();
}
[Test]
public void then_it_redirects_to_the_home_page()
{
SUT.Route.ShouldMapTo<HomeController>(c => c.Index());
}
[Test]
public void then_it_sends_the_user_an_email()
{
SUT.Mailbox().MailMessages.Count().ShouldEqual(1);
}
[Test]
public void then_it_sends_to_the_right_address()
{
SUT.Mailbox().MailMessages[0].To[0].Address.ShouldEqual("test@user.com");
}
[Test]
public void then_it_comes_from_the_expected_address()
{
SUT.Mailbox().MailMessages[0].From.Address.ShouldEqual("registration@specsfor.com");
}
}
}