开发者

How do I give each test its own TestResults folder?

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 开发者_C百科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?


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
    }


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜