Possible to change the filename of approval test

1.2k views Asked by At

I'd like to run an approval test in a loop so that I can test 100-1000s of XML files. I get the serialiser to output to a string and then use that in the Verify() call.

However, I'd like to be able set the verify method to use a different filename for each test. The class & method name is fine, but I'd like to tag it with an additional name to describe the ID of the record being tested in the database.

Is this possible, if so how? e.g.

MyTests.Test_X.ID101.approved.txt

MyTests.Test_X.ID101.received.txt

1

There are 1 answers

1
llewellyn falco On BEST ANSWER

What you are looking for is the

 using (ApprovalResults.ForScenario("ID101"))
 {
    Approvals.Verify(data101);
 }     
 using (ApprovalResults.ForScenario("ID102"))
 {
    Approvals.Verify(data102);
 }

(Probably in a loop)
Whatever you add to the ForScenario will be appended exactly as you are looking for.

Also note that an alternative strategy is to concatenate all the xml into one master long file. Each has it's advantages so choose the right one depending on your situation

Happy Testing!