问题
How do I run MSTest as part of my build process in TeamCity? What are the pitfalls?
回答1:
This answer is specifically for TeamCity 7.1 on Windows, but may apply to other environments.
- In your TeamCity build configuration, on the General Settings page
- Artifact paths:
Artifacts\MSTest => MSTest
- Artifact paths:
- Create a new Command Linebuild step
- Custom script:
if not exist Artifacts\MSTest mkdir Artifacts\MSTest
- Custom script:
- Create a new MSTestbuild step
- List assembly files:
**\bin\**\*.Tests.dll
- Results file:
Artifacts\MSTest\testResults.trx
- List assembly files:
Pitfalls
Using wildcards when specifying which test assemblies to run
You can use wildcards when specifying which test assemblies to run in the MSTest build step, although it is unclear exactly how they work. A bug report has been filed.
The build process doesn't stop when tests fail
Be aware that if some of your tests fail and the build is marked as failed, the MSTest build step itself does not fail. This causes problems if you have build steps after the MSTest build step which you don't want to run if you have test failures (e.g. it may not make sense to produce an installer or documentation of a build you know has bugs). The problem will hopefully be fixed in later versions of TeamCity.
If you want your build process to stop when you have test failures, you can create a new build step that uses the TeamCity REST API to detect if the current build has been marked as failed (remember that when tests fail, the build step is not marked as failed, but the build is), and then fail the current build step explicitly. Example:
- Create a new Powershell build step
- Script: Source code
- Source code: See script below
- Make sure your newly created build step comes immediately after your MSTest build step
- Make sure every build step after this one has Execute step set to Only if all previous steps were successful
Script:
$xml = [xml](curl --request GET http://USERNAME:PASSWORD@HOSTNAME/httpAuth/app/rest/builds/%teamcity.build.id%)
Microsoft.PowerShell.Utility\Select-Xml $xml -XPath "/build" | % { $status = $_.Node.status }
if ($status -eq "FAILURE") {
throw "Failing build step on purpose"
}
来源:https://stackoverflow.com/questions/13212748/how-to-integrate-mstest-in-your-teamcity-build-process