How can I give each test its own TestResults folder?

I have a set of unit tests, each of which contains many methods, each of which produces output in the TestResults folder. At the moment, all test files are mixed up in this folder, but I would like to bring some order into chaos.

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

I know that I can get around adding code for each test so that it produces output in a subfolder, but I was wondering if there is a way to control the location of the output folders using the Visual Studio unit test environment, perhaps using the initialization method on each test class so that have any new tests added automatically their own output folder without having to copy / paste the boilerplate code?

+4
source share
2 answers

I ended up with 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 similar to this:

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

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

0
source

You guess me a little: it depends on what you want to do with the exit? If the result is TestResult.xml, which is analyzed by CruiseControl, why do you need several of them?

[change]

Perhaps you can track folders by grouping tests in a class and setting up the output folder in [TestFixtureSetup]?

[change]

You should use testframework as NUnit, I suppose you are familiar with this.

Than a concrete test class you can 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 } 
0
source

Source: https://habr.com/ru/post/1306501/


All Articles