VSTest:MSTest V2适配器不支持testsettings文件或ForcedLegacyMode设置为true的runsettings.没有测试可用

Jos*_*man 9 visual-studio vstest vstest.console.exe

如何通过.testsettings文件运行单元测试vstest.console.exe?我创建了空的visual studio解决方案,创建了空单元测试项目,添加了Local.testsettings文件作为解决方案项.

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

    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="1109524d-9809-4423-b7fa-fad429ebfd8d" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <Description>These are default test settings for a local test run.</Description>
  <Deployment enabled="false" />
  <Execution hostProcessPlatform="MSIL">
    <TestTypeSpecific>
      <UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
        <AssemblyResolution>
          <TestDirectory useLoadContext="true" />
        </AssemblyResolution>
      </UnitTestRunConfig>
    </TestTypeSpecific>
    <AgentRule name="LocalMachineDefaultRole">
    </AgentRule>
  </Execution>
  <Properties />
</TestSettings>
Run Code Online (Sandbox Code Playgroud)

使用以下命令运行测试时,一切正常:

>> "[path to vstest]/vstest.console.exe" [path to project]\UnitTestProject1.dll
Run Code Online (Sandbox Code Playgroud)

以下命令给出错误.

"[path to vstest]/vstest.console.exe" [path to project]\UnitTestProject1.dll /Settings:[path to settings file]\Local.testsettings
Run Code Online (Sandbox Code Playgroud)

警告:MSTest V2适配器不支持testsettings文件或ForcedLegacyMode设置为true的runsettings.[path]\UnitTestProject1.dll中没有可用的测试.确保已注册测试发现者和执行者,并且平台和框架版本设置是适当的,然后重试.

此外,可以使用/ TestAdapterPath命令指定测试适配器的路径.示例/ TestAdapterPath:

所以我添加了/TestAdapterPath:[project path/bin/Debug]参数.在Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll与发现者和执行人这里位于.但是我没有关于指定测试适配器的最后一句话得到了相同的错误.

我想知道是否有人可以解决这个问题.

小智 31

我有类似的问题,我已经通过以下方式解决了它:

  1. 转到测试 - > 测试设置

  2. 取消选中该\..\..projectTestSettings.testsettings文件

  3. 再次运行测试


Jos*_*man 11

解决方案是使用Visual Studio默认情况下Microsoft.VisualStudio.QualityTools.UnitTestFrameworkMicrosoft.VisualStudio.TestPlatform.TestFramework其添加到单元测试项目中.所以你可以通过删除两个包NuGet.您应该删除MSTest.TestAdapterMSTest.TestFramework安装Microsoft.VisualStudio.QualityTools.UnitTestFramework.Updated.在这些步骤之后将发现您的单元测试.

您还可以阅读以下有关测试框架MSTest V2的有用文章.