質問

I am writing my first ApprovalTest. I need to understand why I am getting the following error when bothg my files are the same.

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.

My Code is

[TestMethod]
        public void About()
        {

            //AspApprovals.VerifyUrl("http://localhost:50011/Home/About");
            MvcApprovals.VerifyMvcPage(new HomeController().About);

        }
役に立ちましたか?

解決

ApprovalTests uses a "golden master" style of verification. Meaning that you will always fail the 1st time you run. Once it fails, but produces the right result, you will move the file over and then it will pass and continue to pass until something changes.

There are multiple ways to create the golden master, but one easy way in via the command line, which is why you are seeing the

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"

this creates the .approved files from the .received file.

You might also want to check out this video on reporters which will help explore other ways to create the golden master and view the generated results: Reporter video

or this video, about verifying MVC pages MVC Approvals Video

Happy Testing!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top