无法从jenkins和`runtests.cmd`文件运行specflow测试

时间:2017-10-06 11:58:27

标签: c# jenkins msbuild mstest specflow

我试图从jenkins运行specflow测试但所有测试都在运行期望specflow测试(规范流测试应该失败 - 断言1 == 2)。

注意:使用Visual Studio 2017,包括规格流在内的所有测试都按预期运行。

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

enter image description here

enter image description here

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 Studio\2017\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 Studio\2017\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运行?这与测试不能在詹金斯运行的原因有关吗?

1 个答案:

答案 0 :(得分:1)

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

您必须使用vstest.console.exe而不是mstest.exe 当您使用MSTest作为测试运行器时,MSTest.exe是跑步者。

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