【问题标题】:make MSTest not building&deploying, and run on the same folder使 MSTest 不构建和部署,并在同一文件夹上运行
【发布时间】:2016-07-12 16:07:51
【问题描述】:

我必须使用 MSTest 运行我们的测试,我遇到的问题是 MSTest 在许多子文件夹中创建和运行(TestResults 是根文件夹),并且我们的测试引用了项目其他部分中的一些脚本,因此如果从与解决方案不同的路径执行,它们将失败。

有什么方法可以强制 MSTest 不构建和部署解决方案,而只是在我启动它的同一文件夹上运行测试(即 bin/Debug)?我一直在为 .testsettings 文件苦苦挣扎,但无法走得太远。

【问题讨论】:

    标签: testing deployment mstest


    【解决方案1】:

    不确定我的问题是否正确,但我认为答案是肯定的。并且肯定是 mstest 不需要构建程序集。您可以指向任何包含 [TestClass] / [TestMethod] 的程序集,mstest 将在不进行任何编译的情况下运行测试。

    这是一个例子: 使用 Microsoft.VisualStudio.TestTools.UnitTesting;

    namespace UnitTest
    {
        [TestClass]
        public class UnitTest1
        {
            [TestMethod]
            public void TestMethod1()
            {
            }
        }
    }
    

    只需在 VS 中使用 msbuild 构建它。这将创建以下程序集。在我的情况下是:

    UnitTest.dll
    

    下:

    C:\tmp\unittest\UnitTest\UnitTest\bin\Debug
    

    然后你只需运行:

    C:\tmp\unittest\UnitTest\UnitTest\bin\Debug>mstest /testcontainer:UnitTest.dll
    

    请不要在这里指向任何 dll 文件。

    输出(和命令):

    C:\tmp\unittest\UnitTest\UnitTest\bin\Debug>mstest /testcontainer:UnitTest.dll
    Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    Loading UnitTest.dll...
    Starting execution...
    
    Results               Top Level Tests
    -------               ---------------
    Passed                UnitTest.UnitTest1.TestMethod1
    1/1 test(s) Passed
    
    Summary
    -------
    Test Run Completed.
      Passed  1
      ---------
      Total   1
    Results file:  C:\tmp\unittest\UnitTest\UnitTest\bin\Debug\TestResults\jocke_DESKTOP-S6MP97G 2016-07-12 21_16_40.trx
    Test Settings: Default Test Settings
    
    C:\tmp\unittest\UnitTest\UnitTest\bin\Debug>
    

    【讨论】:

    • 我正在 /bin/debug 文件夹中执行与您相同的命令。问题是 MSBuild 创建了一个 TestResult 文件夹、一个“user_machine timestamp”文件夹和一个 Out 文件夹,其中包含所有测试的 dll。我的理解是它从 \TestResults\user_machine timestamp\Out 文件夹执行 dll,而我的测试要通过它们必须从 /bin/debug 文件夹执行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多