简体   繁体   English

如何为每个测试提供自己的TestResults文件夹?

[英]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. 我有一组单元测试,每个测试都有一堆方法,每个方法都在TestResults文件夹中产生输出。 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? 我知道我可以在每个测试中添加代码以使其在子文件夹中生成输出,但我想知道是否有办法使用Visual Studio单元测试框架控制输出文件夹位置,也许使用初始化方法每个测试类,以便添加任何新测试自动获得自己的输出文件夹,而无需复制/粘贴样板代码?

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? 如果输出是由CruiseControl解析的TestResult.xml,为什么你想要多个?

[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] ? 您可以通过在类中包含测试组并在[TestFixtureSetup]中设置输出文件夹来跟踪文件夹?

[Edit] [编辑]

You should use a testframework like NUnit, I assume you are familiar with that. 您应该使用像NUnit这样的测试框架,我假设您熟悉它。

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 我只记得将单元测试的所有输出都TestDir

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用自己的DataTemplate DependencyProperty实现WPF控件? - How do I implement a WPF control with its own DataTemplate DependencyProperty? 如何在多租户主机的自己的应用程序域中托管可能的恶意代码? - How do I host possibly malicious code in its own app domain in a multi-tenant host? 如何在MSpec中的每个测试中运行设置和拆卸代码? - How do I run setup and teardown code with each test in MSpec? 如何强制执行单元测试以使用主应用程序根路径而不是TestResults? - How can I enforce the unit tests to use the main applications root path but not the TestResults? 如何测试现有的托管.NET .dll以查看其32位还是64位? - How do I test an existing managed .NET .dll to see if its 32-bit or 64-bit? 如何将方法作为属性参数? - How do I give a method as an attribute argument? 如何为目录中的每个文件运行Visual Studio单元测试? - How do I run a Visual Studio unit test for each file in a directory? C# TestProject - 如何为每个测试获取 CodeFilePath 和 LineNumber? - C# TestProject - How do I get CodeFilePath & LineNumber for each test? “主文件夹”的C#数据结构-这应该是它自己的实体吗? - C# Data Structures for “Home Folder” - should this be its own entity? 如何测试ActionFilter? - How do I test an ActionFilter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM