在 mstest/.NET Core 1.1 单元测试中获取测试部署目录

问题描述 投票:0回答:1

如何在 mstest/.NET Core 1.1 单元测试中获取测试部署目录?

详情

我正在尝试在 .NET Core 1.1 中重新创建基于 mstest 和 .NET Framework 的测试。以前有代码通过使用公开的测试上下文属性来检索测试部署目录,如下面的代码块。但在 .NET Core 中,TestContext 对象似乎不再具有 TestDeploymentDir 属性。

    public TestContext TestContext
    {
        get
        {
            return this.testContextInstance;
        }

        set
        {
            this.testContextInstance = value;
        }
    }
    ...
    // This worked in .NET Framework, but TestDeploymentDir is not available in .NET Core.
    // What can I use as a replacement?
    string deploymentPath = this.TestContext.TestDeploymentDir
    ...

我发现 TestDeploymentDir 已被弃用,但它的替代 DeploymentDirectory 也不可用。 (参考:https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcontext.deploymentdirectory.aspx

c# unit-testing .net-core mstest
1个回答
0
投票

就像作者提到的那样,

TestContext.TestDeploymentDir
已被弃用并被
TestContext.DeploymentDirectory
取代。如果它不可用,您可能像我一样安装了错误的 NuGet 包。 如果您安装 NuGetPackage MSTest.TestFramework,则可用。

© www.soinside.com 2019 - 2024. All rights reserved.