As I am building out our CI environment with TeamCity (man, this is a great product) I finally had to tackle something that I have been putting off for the past few weeks. Adding the tests results to TeamCity from our various components which use MSTest. I have already added NUnit results, as that is done for you out of the box with TeamCity. Now before you ask ‘Why are you using both MSTest and NUnit’? We simple. Most our older tests are done with MSTest (god, I really, really hate MSTests – More here) and most our newer (less than 6 months old) code is in NUnit.
I really thought that adding MSTests would be a pain, but as it turned out it was not. I searched Jetbrains knowledge base and found this posting which talked about what you needed to do to add MSTest results to your build.
Basically you only need to add this line to your build (assuming NAnt here) file.
##teamcity[importData id='mstest' file='<path to .trx file>']
When I say add it, I simply mean doing a echo of this information. This is possible because TeamCity watches the standard output stream for various commands, and this is one of the commands you can use.
Here is how I added this to my build file:
<target name="tests.run.HL7" >
<property name="test.resultFile.name" value="${tests.output.dir}/testResults.trx" />
<if test="${file::exists(test.resultFile.name)}">
<echo message="Deleting old test run file ${test.resultFile.name}" />
<delete file="${test.resultFile.name}" />
</if>
<exec program="MSTest.exe"
commandline="/testcontainer:${build.dir}${communication.tests.file} /testcontainer:${build.dir}${httpImportService.tests.file} /testcontainer:${build.dir}${messagesCore.tests.file} /testcontainer:${build.dir}${messageHandler.tests.file} /resultsfile:${tests.output.dir}/testResults.trx"
basedir="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE"
failonerror="false"
/>
<!--- This is the needed line for TeamCity -->
<echo message="##teamcity[importData id='mstest' file='…path to output….\Output_AutomatedBuild\Output_UnitTests\testResults.trx']" />
</target>
As you can see this is real easy. Once you have this in your build file simply re-run your build in TeamCity and check your build results. If you did every thing correct you should have a ‘Test’ tab. If something went wrong check your output logs as it should tell you what blew up.
Hope this helps someone.
Till next time,
[--- Check out www.Dimecasts.net ---]
Posted
12-20-2008 9:39 AM
by
Derik Whittaker