Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place approval file for approvaltests in a folder of their own?

I can't find out how to move the .approved. files to a folder of their own in Approval-tests. I guess the information is there somewhere - I just can't find it.

https://github.com/approvals/ApprovalTests.Net

like image 217
LosManos Avatar asked Mar 14 '13 20:03

LosManos


2 Answers

The current way to do it is by annotating the fixture or at the assembly level with

[ApprovalTests.Namers.UseApprovalSubdirectory("foldername")]

If you are before version 3.2 you can create a custom namer that will handle this if you want to. The basics are:

Override the namer for your framework, and override the method SourcePath

public string SourcePath
{
    get { return base.SourcePath + @"\yourSubfolder"; }
}

Then you need to add your new namer to the stack

StackTraceParser.AddParser(new MyNamer());

Although I would ask why you want the separation of the approval files to a subdirectory of your tests? I'm sure there is a good reason, but I have found it nicer to keep them closer to my actual tests.

like image 87
llewellyn falco Avatar answered Oct 23 '22 03:10

llewellyn falco


From a look at the code from Git, it looks like Llewellyn just added the following attribute...

[UseApprovalSubdirectory("Approvals")]

.. to place the approvals in a subfolder called "Approvals". This appears to work at the test and class level.

This helps keep those approvals organized when there are many approval files for each unit test file.

like image 21
user3006539 Avatar answered Oct 23 '22 03:10

user3006539