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.
-
Itβs now in wiki https://github.com/approvals/ApprovalTests.Net/wiki/Controlling-where-approved-files-are-saved β Michael Freidgeim Nov 02 '18 at 22:33
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.

- 4,174
- 34
- 47

- 2,281
- 16
- 13
-
1I don't like mixing executing code and data. Now these might be considered the same regarding automatic tests. I'll start with doing as you do - you have used your system longer than I have... β LosManos Mar 15 '13 at 09:54
-
3In defense of why you'd want to do this: if you've got a fair few tests in the same namespace, the number of approval files in the directory can start to hide the relatively few number of test classes (making class navigation harder) β piers7 Dec 10 '14 at 01:31
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.

- 13,322
- 16
- 71
- 114

- 101
- 1
- 3