verifyverify-tests

Does "VerifyTests / Verify" have global settings?


@Simon (https://stackoverflow.com/users/53158/simon)

In the docs it is mentioned how to setup a custom output directory for Verify and it works fine, but it is pain to do it for every test.

await Verify("value")
    .UseDirectory("CustomDirectory");

ApprovalTests have a global UseApprovalSubdirectory which solves this issue. So I wonder is there anything similar in VerifyTests / Verify?
The reason is that VS2022 does not allow renaming nested files, so I need to go to the file explorer and rename files there (pain...)

Related GitHub issue: https://github.com/VerifyTests/Verify/issues/482


Solution

  • You should be able to use DerivePathInfo to achieve this. So in your case

    VerifierSettings.DerivePathInfo(
        (sourceFile, projectDirectory, type, method) =>
        {
            return new(
                directory: Path.Combine(projectDirectory, "CustomDirectory"),
                typeName: type.Name,
                methodName: method.Name);
        });