分析代码覆盖率时单元测试失败

时间:2019-07-02 09:59:45

标签: c# unit-testing code-coverage

我有一个包含许多UnitTests的项目。当Test-> Run-> All Tests时,所有测试均成功。但是如果Test-> Analyze Code Coverage,则使用内部Process.Start()进行的测试将失败。

我正在将VS 2017 Enterprise与Microsoft.NET.Test.Sdk 15.8.0,MSTest.TestAdapter 1.2.1和MSTest.TestFramework 1.2.1一起使用。我项目的框架是NetCore 2.0。

以下是来自Process.StandardError的错误消息:


    [Error] System.ArgumentException: Item has already been added. Key in dictionary: 'CODE_COVERAGE_SESSION_NAME'  Key being added: 'CODE_COVERAGE_SESSION_NAME'
    [Error]    at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
    [Error]    at System.Environment.ToHashtable(IEnumerable`1 pairs)
    [Error]    at System.Environment.GetEnvironmentVariables()
    [Error]    at System.Diagnostics.ProcessStartInfo.get_Environment()
    [Error]    at Microsoft.DotNet.Cli.Utils.ForwardingAppImplementation.GetProcessStartInfo()
    [Error]    at Microsoft.DotNet.Cli.Utils.MSBuildForwardingAppWithoutLogging.GetProcessStartInfo()
    [Error]    at Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingApp.GetProcessStartInfo()
    [Error]    at Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingApp.Execute()
    [Error]    at Microsoft.DotNet.Tools.Restore.RestoreCommand.Run(String[] args)
    [Error]    at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
    [Error]    at Microsoft.DotNet.Cli.Program.Main(String[] args)
    [Error] 

有人知道如何解决这个奇怪的问题吗?谢谢〜

0 个答案:

没有答案