【问题标题】:no test available..test through exe using build tools and test agent on VM没有可用的测试..通过 exe 在 VM 上使用构建工具和测试代理进行测试
【发布时间】:2020-02-03 17:53:56
【问题描述】:

我正在尝试在 Windows VM 上运行所有包含的 exe(使用 Costura 创建)。根据this SO question 中的回答,我已经安装了测试代理和构建工具,并尝试通过此命令运行 exe

C:\Users\..\Desktop>"C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" MyExeName.exe /Tests: MyTestName

在 VM 上,我启动代理并发出上述命令,但收到错误 No test is available in C:\Users\..\Desktop\MyExeName.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

exe 在本地机器上运行良好,使用相同的命令并开始测试。在本地,我有 VS2019 和所有代码。在 VM 上,我不能将 VS 和代码库作为要求。

编辑: 我注意到(通过 ILSpy)在引用下的 dot exe 中,没有对此 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll 的引用,但是 dll 存在于资源中。

【问题讨论】:

  • 有人问这个吗?
  • 您可以使用 /ListDiscoverers 和 /ListExecutors 参数来查找 VM 上的测试发现者和执行者。只是为了排除一些事情。 docs.microsoft.com/en-us/visualstudio/test/…
  • @Kevin 当我运行它时,我没有看到 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter 包,但是我看到了 Default Executor Uri: executor://mstestadapter/v1 但为此列出的包不同 Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.MSTestDiscoverer
  • 所以看来对Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter 的引用确实是没有发现测试的问题。在创建 exe 时如何包含该引用而不破坏它,知道吗?
  • 尝试将MSTest.TestAdapter添加为包nuget.org/packages/MSTest.TestAdapter

标签: c# .net mstest


【解决方案1】:

我可以重现这个错误...我对我的 csproj 文件做了一些实验,结果你必须在控制台 csproj 文件中添加一个 Import 标签。这与您的测试代理或测试类无关。

检查你的 package.config(ps。这是 2019,所以检查你的版本)必须添加 MSTest.TestAdapter。

<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net48" />

其次,将 Import 标签添加到您的 csproj 文件中。 (并再次检查您的版本)

<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />

在导入此项目时,您的项目中会添加更多项目。

这会导致这个输出

请参阅下面的测试用例 1(不工作)和 2(工作)的屏幕截图

测试 1:

测试 2:

我希望这对你有用!

解决方案和项目:

【讨论】:

  • 我能够通过this 的帮助克服该错误,即通过在命令行中传递 /TestAdapterPath。但是,我不想传递该参数并以某种方式将所有内容构建到 exe 中。根据你的回答,我看了看,这两行都已经在我的项目中了。 &lt;package id="MSTest.TestAdapter" version="2.1.0" targetFramework="net472" /&gt;
  • 和&lt;Import Project="packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props')" /&gt;,如果您知道如何将所有内容构建到 exe 中,我很乐意接受答案:)
  • 我的回答仅基于控制台应用程序。我将用我的解决方案的屏幕截图更新我的答案。
猜你喜欢
  • 2019-05-13
  • 2011-11-08
  • 2014-04-28
  • 2022-10-14
  • 2021-04-09
  • 1970-01-01
  • 2020-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多