none
How to execute UnitTests from MSBuild?

    Question

  • Greetings!

    We are trying to setup an automated build framework using MSBuild. As part of the same, we want to integrate invoking the VS 2005 Automated Unit testing framework from within the MSBuild framework. So that after the build process we even have the Unit test report generated using the automated build framework..

    Is there a straight forward way/target to accomplish the same?

    Thanks in advance!
    Gaurav.

    Friday, December 02, 2005 11:45 AM

Answers

  • Hi,

    Do you have Team Build? If so I think you can have it execute the test cases for you. Otherwise you may need to use mstest.exe to execute the test cases for you. There may be a better way to achieve this but I'm not aware of it. If you have to use the mstest.exe to exeucte the tests then you may be able to read the results using the info at: http://channel9.msdn.com/wiki/default.aspx/MSBuild.CanonicalErrorWarningSpec. I've never tried this particular scenario, but it's worth checking into. Let me know what you decide.

    Thanks,
    Sayed Ibrahim Hashimi
    Friday, December 02, 2005 2:07 PM
    Moderator
  • It looks like you have solution for 1). For 2) there is a TestToolsTask where you can define your tests. However, you need test metadata file (*.vsmdi) where your tests are included in a test list. Manish Agarwal has some related blogs regarding the big build project files (http://blogs.msdn.com/manishagarwal/default.aspx) where you might be able to get some useful information how to add TestToolsTask target. You can also use the post-build process to run your tests using mstest.exe. With mstest.exe all you need is your UT assembly files. And for last part, 3), you need to have TFS with team project and completed build type to be able to publish your results.

    Thanks,
    Bata Chadraa,
    VSTT

    Monday, December 05, 2005 10:02 PM
  • Thanks for the inputs!

    Going by some blogs, the testToolsTask seems to have some issues.

    What i've finally worked out for Step 2 is use the Exec task to invoke MSTest.exe and have the tests executed. The command used is

    <Exec Command="MSTest.exe /testcontainer:My.dll />

    Though the Publish part is still an open issue without the TFS.

    Cheers!
    Gaurav.

    Tuesday, December 06, 2005 12:24 PM

All replies

  • Hi,

    Do you have Team Build? If so I think you can have it execute the test cases for you. Otherwise you may need to use mstest.exe to execute the test cases for you. There may be a better way to achieve this but I'm not aware of it. If you have to use the mstest.exe to exeucte the tests then you may be able to read the results using the info at: http://channel9.msdn.com/wiki/default.aspx/MSBuild.CanonicalErrorWarningSpec. I've never tried this particular scenario, but it's worth checking into. Let me know what you decide.

    Thanks,
    Sayed Ibrahim Hashimi
    Friday, December 02, 2005 2:07 PM
    Moderator
  • Greetings !

    We are using VS2005 Team Suite for our development, but don't have the TFS server setup at the backend as yet. Is there a default/standard command available for the same? So drilling this point further we need a way to

    1) Build our UT Project : Possible, since its simply adding an entry of CSProj file into the build list
    2) Execute the UT Project : ??? Do we need to execute the MSTest cmd or is there some other way (Target) to accomplish the same?
    3) Publish the Test Results: ? I think looking around MSTest help, it seems that we need Team explorer for the same? ????

    But can someone clarify on this whole process to help acheive the above 3 sequences or point to a location where we can have better understanding of the whole sequence.

    Thanks in advance!
    Gaurav.
    Monday, December 05, 2005 5:48 AM
  • It looks like you have solution for 1). For 2) there is a TestToolsTask where you can define your tests. However, you need test metadata file (*.vsmdi) where your tests are included in a test list. Manish Agarwal has some related blogs regarding the big build project files (http://blogs.msdn.com/manishagarwal/default.aspx) where you might be able to get some useful information how to add TestToolsTask target. You can also use the post-build process to run your tests using mstest.exe. With mstest.exe all you need is your UT assembly files. And for last part, 3), you need to have TFS with team project and completed build type to be able to publish your results.

    Thanks,
    Bata Chadraa,
    VSTT

    Monday, December 05, 2005 10:02 PM
  • Thanks for the inputs!

    Going by some blogs, the testToolsTask seems to have some issues.

    What i've finally worked out for Step 2 is use the Exec task to invoke MSTest.exe and have the tests executed. The command used is

    <Exec Command="MSTest.exe /testcontainer:My.dll />

    Though the Publish part is still an open issue without the TFS.

    Cheers!
    Gaurav.

    Tuesday, December 06, 2005 12:24 PM
  • I've got one more question about this topic:
    I would like to execute unit tests like above in an MSBUILD file and to distinguish between the 2 cases:
    all unit tests successful and not all unit tests successful. Depending on the outcome of the unit tests (successufl / not successful) I would like to do other actions. how can I make this query to decide which action to take?
    Thursday, December 08, 2005 5:55 PM