简体   繁体   English

在Visual Studio 2012中两次运行某些单元测试

[英]Run some unit tests twice in Visual Studio 2012

I have a straightforward unit test class like so: 我有一个简单的单元测试类,如下所示:

    [TestClass]
    public class SomeTests
    {
        [TestMethod]
        public void Test1()
        {
            // make some assertions
        }

        [TestMethod]
        public void Test2()
        {
            // make some assertions
        }
        // ...
        [TestMethod]
        public void Test50()
        {
            // make some assertions
        }
    }

and I basically want to run Test1..Test50 twice via the "Run All" command. 我基本上想通过“全部运行”命令两次运行Test1..Test50。 Once with App.config like so: 一次使用App.config像这样:

<appSettings>
    <add key="SomeSetting" value="true"/>
</appSettings>

and once with App.config like so: 然后使用App.config像这样:

<appSettings>
    <add key="SomeSetting" value="false"/>
</appSettings>

Being lazy, I don't want to refactor & parameterize 50 tests. 懒惰,我不想重构和参数化50个测试。 And obviously I don't want 50 duplicate tests. 显然,我不想进行50次重复测试。

I'm having a bit of a brain fart over this, apologies if it's blindingly obvious. 我对此有点放屁,如果这是显而易见的话,我深表歉意。

make SomeTests abstract. 使SomeTests抽象。

Add two new projects, with the two different .config files. 添加两个新项目,以及两个不同的.config文件。

In each project add a TestClass that inherits from SomeTests. 在每个项目中,添加一个继承自SomeTests的TestClass。

Run all will now run both sets of tests. 全部运行现在将运行两组测试。

Create two Test Settings. 创建两个测试设置。 Click Enable Deployment under the Deployment section. 单击“部署”部分下的“启用部署”。 Add your two different App.Config files (one to each Test Settings). 添加您的两个不同的App.Config文件(每个测试设置一个)。 Execute your tests, then swap to the other TestSettings and execute them again. 执行测试,然后交换到其他TestSettings并再次执行它们。

Might be a way to run with all testsettings, but I haven't found it. 可能是所有测试设置都可以运行的一种方法,但是我还没有找到它。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM