16

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

Simon
  • 33,714
  • 21
  • 133
  • 202
LosManos
  • 7,195
  • 6
  • 56
  • 107

2 Answers2

18

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.

piers7
  • 4,174
  • 34
  • 47
llewellyn falco
  • 2,281
  • 16
  • 13
  • 1
    I 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
  • 3
    In 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
8

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.

Carlo V. Dango
  • 13,322
  • 16
  • 71
  • 114
user3006539
  • 101
  • 1
  • 3