views:

61

answers:

2

I have a set of unit tests, each with a bunch of methods, each of which produces output in the TestResults folder. At the moment, all the test files are jumbled up in this folder, but I'd like to bring some order to the chaos.

Ideally, I'd like to have a folder for each test method.

I know I can go round adding code to each test to make it produce output in a subfolder instead, but I was wondering if there was a way to control the output folder location with the Visual Studio unit test framework, perhaps using an initialization method on each test class so that any new tests added automatically get their own output folder without needing copy/pasted boilerplate code?

A: 

You have me guessing a bit: it depends what you want to do with the output? If the output is TestResult.xml that is parsed by CruiseControl, why would you want multiple of those?

[Edit]

You might be able to keep track of the folders by having groups of your tests in a class and setup the outputfolder in the [TestFixtureSetup] ?

[Edit]

You should use a testframework like NUnit, I assume you are familiar with that.

Than for a specific testclass you could do:

[TestFixture]
public class MyOutPutTests
{

    private string folder;

    [SetUp]
    public void InitializeFolder()
    {
        this.folder = @"d:\MyFirstOutputTests";
    }

    [Test]
    public void OutImages()
    {
       ... write to this.folder
    }

    [Test]
    public void OutputLogs()
    {
       .. write logs to this.folder
    }
Hace
Each test produces one or more logs, images and output files, which I wish to inspect visually.
izb
Sounds like TestFixtureSetup has promise.. could you give an example?
izb
A: 

I ended up doing this:

    private string TestDir;

    [TestInitialize]
    public void InitilizeTests()
    {
        TestDir = TestContext.TestDir + @"\Out\" +
                this.GetType().Name + @"." + TestContext.TestName + @"\";

        Directory.CreateDirectory(TestDir);
    }

This creates a Directory structure like this:

TestResults
    <test run>
        Out
            <test class name>.<test method name>

And I just remember to direct all output from a unit test into TestDir

izb