Validate multiple images using approvaltest

I have a way to generate some images (1. JPG, 2. JPG...) and write them to the file system I want to verify the result of this method with approvaltest The problem is approvals Verify (image) names the received and approved files when naming the test method Therefore, I cannot verify multiple images through one test

How do I validate multiple images in one test?

Solution

You can use namerfactory to change the information attached to the end of the file Proceed to the next test

[TestFixture]
class Program
{
    [Test]
    [UseReporter(typeof(WinMergeReporter))]
    public void Test1()
    {
        var image1 = @"firstImage.png";
        var image2 = @"secondImage.png";

        NamerFactory.AdditionalInformation = Path.GetFileNameWithoutExtension(image1);
        ApprovalTests.Approvals.Verify(image1);

        NamerFactory.AdditionalInformation = Path.GetFileNameWithoutExtension(image2);
        ApprovalTests.Approvals.Verify(image2);
    }
}

Approval tests creates two files with firstimage and secondimage before ending Refer to the screenshot to clarify:

My object is a string, but for your image, everything is the same You can call approvals. As before Verify (image), but just change additionalinformation as in the example

Note: I do not recommend verifying two images in one test, because if one verification fails – the next verification will not be performed And the approval test cannot connect images and verify them in one step, at least if you do it yourself

Edit: for Java tries to use, located in namerfactory

public static void asMachineSpecificTest(Function0<String> environmentLabeller)
{
    additionalInformation = environmentLabeller.call();
}

And provide the appropriate function, which will return the name of the image

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>