我正在写我的第一个ApprovalTest。我需要理解为什么当我的文件都相同时我会收到以下错误。
move /Y "C:\SampleMvc-master\SampleMvc-master\SampleMvc.Tests\Controllers\GoldenMasterTest.About.received.html" "C:\SampleMvc-master\SampleMvc-master\SampleMvc.Tests\Controllers\GoldenMasterTest.About.approved.html"
move /Y "C:\SampleMvc-master\SampleMvc-master\SampleMvc.Tests\Controllers\GoldenMasterTest.About.received.html" "C:\SampleMvc-master\SampleMvc-master\SampleMvc.Tests\Controllers\GoldenMasterTest.About.approved.html"
Test method SampleMvc.Tests.Controllers.GoldenMasterTest.About threw exception:
ApprovalTests.Core.Exceptions.ApprovalMismatchException: Failed Approval: Received file C:\SampleMvc-master\SampleMvc-master\SampleMvc.Tests\Controllers\GoldenMasterTest.About.received.html does not match approved file C:\SampleMvc-master\SampleMvc-master\SampleMvc.Tests\Controllers\GoldenMasterTest.About.approved.html.
我的代码是
[TestMethod]
public void About()
{
//AspApprovals.VerifyUrl("http://localhost:50011/Home/About");
MvcApprovals.VerifyMvcPage(new HomeController().About);
}
答案 0 :(得分:2)
ApprovalTests使用“黄金大师”的验证方式。这意味着你第一次跑步时总会失败。一旦失败,但产生了正确的结果,你将移动文件,然后它将通过并继续通过,直到发生变化。
有多种方法可以创建黄金大师,但通过命令行可以轻松实现,这就是为什么你会看到
move / Y“C:\ SampleMvc-master \ SampleMvc-master \ SampleMvc.Tests \ Controllers \ GoldenMasterTest.About.received.html”“C:\ SampleMvc-master \ SampleMvc-master \ SampleMvc.Tests \ Controllers \ GoldenMasterTest.About.approved.html“
这会从.received文件中创建.approved文件。
您可能还想查看有关记者的视频,这有助于探索创建黄金大师的其他方法并查看生成的结果: Reporter video
或此视频,关于验证MVC页面 MVC Approvals Video
快乐测试!