Dot-Net

如何讓 TeamCity 使用 MSTest 執行測試?

  • December 5, 2011

我想弄清楚如何讓 TeamCity 執行我的 MSTests。我已經使用以下參數設置了建構步驟:

  • MSTest.exe 的路徑: %system.MSTest.10.0%
  • 列出程序集文件: Projects\Metadude。.Tests\bin\Debug\Metadude。.Test.dll
  • MSTest 執行配置文件: Local.testsettings

但是,當此步驟執行時,它不會執行任何測試。這是日誌的輸出:

[02:13:49]: Step 2/2: Run Unit Tests (MSTest)
[02:13:49]: [Step 2/2] Starting: "D:\Program Files (x86)\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.NUnitLauncher.exe" #TeamCityImplicit
[02:13:49]: [Step 2/2] in directory: D:\Program Files (x86)\TeamCity\buildAgent\work\1f82da3df0f560b6
[02:13:50]: [Step 2/2] Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
[02:13:50]: [Step 2/2] Copyright (c) Microsoft Corporation. All rights reserved.
[02:13:50]: [Step 2/2]
[02:13:50]: [Step 2/2] Please specify tests to run, or specify the /publish switch to publish results.
[02:13:50]: [Step 2/2] For switch syntax, type "MSTest /help"
[02:13:50]: [Step 2/2] Process exited with code 1
[02:13:50]: Publishing internal artifacts
[02:13:50]: [Publishing internal artifacts] Sending build.finish.properties.gz file
[02:13:50]: Build finished

我嘗試使用以下命令指定要執行的測試:

  • 測試: Tests.Metadude.Core.Extensions.StringExtensionsTests

但這不起作用。我似乎在 Google 上找不到任何與 TeamCity 中的 MSTest 建構步驟相關的文件。

更新 好吧,我是個白痴。好吧,這可能有點苛刻,但是測試程序集的程序集名稱中缺少一個“s”。不過,在建構日誌中獲得這種效果會很好。

首先,確保您要測試的程序集存在於該位置。

IE

您的相對路徑:Projects\Metadude..Tests\bin\Debug\Metadude..Test.dll

但是,如果您的文件不存在,我希望 TC 會記錄一些內容。看起來它MSTest以某種方式在沒有任何參數的情況下執行。

如果您確定路徑正確,請嘗試不指定.testsettings文件以查看會發生什麼。我在沒有這個的情況下在 TC 中成功使用了 MSTest(但你可能需要它)。我正在做的另一件事是我指定 FULL 路徑MSTest.exe,即

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe

而不是他們的變數'%system.MSTest.10.0%'

我不記得為什麼我這樣做了,但會有一個很好的理由(比如在使用他們的變數時它不起作用)

引用自:https://stackoverflow.com/questions/8382632