Is there a way I can use a different extension than .txt such as .log or .csv when using ApprovalTests?

171 Views Asked by At

I want the content to remain a text file, so code such as:

Approvals.Verify("some actual result as text");

Should continue to work. But I would like the approval tests to write to a ..approval.csv file or a ..approval.log file instead of ..approval.txt file.

I looked through the code and I think I may need to create a custom IApprovalWriter, but I also notice that the ExtensionWithDot property is read/write, so I'm wondering how this can be set.

Does anyone know how to do that?

1

There are 1 best solutions below

0
llewellyn falco On
ApprovalTests.Approvals.Verify(WriterFactory.CreateTextWriter(text, fileExtensionWithoutDot));

or for your example:

Approvals.Verify(WriterFactory.CreateTextWriter("some actual result as text", "log"));

Happy Testing!