无法 运行 来自 jenkins 和 `runtests.cmd` 文件的 specflow 测试

Can't run specflow tests from jenkins and `runtests.cmd` file

我正在尝试 运行 来自 jenkins 的 specflow 测试,但所有测试都是 运行ning 期待 specflow 测试(spec flow 测试应该失败 - 断言 1==2)。

注意: 使用 visual studio 2017,包括规范流程在内的所有测试都按预期 运行ning。

Jenkins 配置:(没有错误但有警告)

Jenkins 控制台输出:

...
Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.17
Path To MSTest.exe: C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\Common7\IDE\MSTest.exe
Delete old result file file:/C:/Program%20Files%20(x86)/Jenkins/workspace/new%203/TestResults.trx
[new 3] $ "C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\Common7\IDE\MSTest.exe" /resultsfile:TestResults.trx /noisolation "/testcontainer:C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.Tests\bin\Debug\WebApplication2.Tests.dll"
Microsoft (R) Test Execution Command Line Tool Version 15.0.26621.2
Copyright (c) Microsoft Corporation. All rights reserved.

Loading C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.Tests\bin\Debug\WebApplication2.Tests.dll...
Starting execution...
Results               Top Level Tests
-------               ---------------
Passed                WebApplication2.Tests.Controllers.HomeControllerTest.About
Passed                WebApplication2.Tests.Controllers.HomeControllerTest.Contact
Passed                WebApplication2.Tests.Controllers.HomeControllerTest.Index
3/3 test(s) Passed

Summary
-------
Test Run Warning.
  Passed  3
  ---------
  Total   3
Results file:  C:\Program Files (x86)\Jenkins\workspace\new 3\TestResults.trx
Test Settings: Default Test Settings

Run has the following issue(s):
Warning: Test Run deployment issue: The assembly or module 'WebGrease' directly or indirectly referenced by the test container 'c:\program files (x86)\jenkins\workspace\new 3\webapplication2.tests\bin\debug\webapplication2.tests.dll' was not found.
[MSTEST-PLUGIN] INFO processing test results in file(s) TestResults.trx
[MSTEST-PLUGIN] INFO processing report file: C:\Program Files (x86)\Jenkins\workspace\new 3\TestResults.trx
[MSTEST-PLUGIN] WARNING Unable to delete the file C:\Program Files (x86)\Jenkins\workspace\new 3\temporary-junit-reports
[MSTEST-PLUGIN] INFO This file is a reserved temporary file. You can delete it safely.
[MSTEST-PLUGIN] INFO XML coverage report file not found: C:\Program Files (x86)\Jenkins\workspace\new 3\vstest.coveragexml

[MSTEST-PLUGIN] INFO XML coverage report file not found: C:\Program Files (x86)\Jenkins\workspace\new 3\TestResults.coveragexml

Finished: SUCCESS

当我运行runtests.cmd有多个错误:

C:\Users\stava\source\repos\WebApplication2\WebApplication2.Tests>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe "" 
Microsoft (R) Build Engine version 4.7.2053.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 05/10/2017 23:38:25.
Project "C:\Users\stava\source\repos\WebApplication2\WebApplication2.Tests\WebApplication2.Tests.csproj" on node 1 (default targets).
Project file contains ToolsVersion="15.0". This toolset may be unknown or missing, in which case you may be able to resolve this by installing the appropriate version of MSBuild, or the build may have been forced to a particular ToolsVersion for policy reasons. Treating the project as if it had ToolsVersion="4.0". For more information, please see http://go.microsoft.com/fwlink/?LinkId=291333.
Project "C:\Users\stava\source\repos\WebApplication2\WebApplication2.Tests\WebApplication2.Tests.csproj" (1) is building "C:\Users\stava\source\repos\WebApplication2\WebApplication2\WebApplication2.csproj" (2) on node 1 (default targets).
C:\Users\stava\source\repos\WebApplication2\WebApplication2\WebApplication2.csproj(229,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Done Building Project "C:\Users\stava\source\repos\WebApplication2\WebApplication2\WebApplication2.csproj" (default targets) -- FAILED.
Done Building Project "C:\Users\stava\source\repos\WebApplication2\WebApplication2.Tests\WebApplication2.Tests.csproj" (default targets) -- FAILED.

Build FAILED.

"C:\Users\stava\source\repos\WebApplication2\WebApplication2.Tests\WebApplication2.Tests.csproj" (default target) (1) ->
"C:\Users\stava\source\repos\WebApplication2\WebApplication2\WebApplication2.csproj" (default target) (2) ->
  C:\Users\stava\source\repos\WebApplication2\WebApplication2\WebApplication2.csproj(229,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.19

为什么测试 运行 完美地形成了 VS 而无法从 runtests.cmd 运行?这与为什么在 jenkins 中测试不 运行 有关吗?

我假设您使用的是 SpecFlow+Runner,因为您有 runtests.cmd.
在这种情况下,请查看如何使用它配置 Jenkins 的文档:http://specflow.org/plus/documentation/SpecFlowPlus-and-Jenkins/

您必须使用 vstest.console.exe 而不是 mstest.exe MSTest.exe 是您使用 MSTest 作为测试运行器时的运行器。

如果您没有使用 SpecFlow+Runner,请查看您的单元测试运行器的文档。