Executing Tests with MSTest

You can also review our Telerik TV episode on Executing Tests with MSTest for a video walk-through of this process.

  1. Open Visual Studio. Create a project containing two tests. In this example, I've create two simple Web Tests: GoogleSearch and BingSearch.
  2. Click Test Windows Test List Editor.
  3.  

     

  4. Right click List of Tests and choose New Test List.
  5.  

     

  6. Name the New Test List and click OK.
  7.  

     

  8. From the Test View pane, drag and drop the tests into the Test List Editor and Save the project.
  9.  

     

  10. Close Visual Studio and open the Visual Studio Command Prompt.
  11. Navigate to the project's directory.
    • C:\Users\Admin\Documents\Visual Studio 2010\Projects\MSTest-Tutorial\MSTest-Tutorial

     

  12. To execute a single test, enter the following:
    • mstest /testcontainer:.\GoogleSearch.tstest

     

     

     

  13. To execute a test list, enter the following:
    • mstest /testlist:SampleTestList /testmetadata:..\MSTest-Tutorial.vsmdi

     

     

  14. Open Visual Studio and load the same project. Go the Solution Explorer pane.
  15. Right click "Solution Items"and choose Add New Item.
  16.  

     

    Note: In Visual Studio 2008, the default configuration file is LocalTestRun.testrunconfig.

     

  17. Highlight Test Settings on the left, again in the center, and give it a unique name. Click Add.
  18.  

     

  19. The Test Settings window appears. Click Telerik Test Studio on the left, and then click the Web tab.
  20.  

     

  21. Change the browser to Firefox and click Apply and Close. Save the project.
  22. Close Visual Studio and open the Visual Studio Command Prompt.
  23. Navigate to the project's directory.
    • C:\Users\Admin\Documents\Visual Studio 2010\Projects\MSTest-Tutorial\MSTest-Tutorial

     

  24. To execute a test list with a custom settings file:
    • mstest /testlist:SampleTestList /testmetadata:..\MSTest-Tutorial.vsmdi /testsettings:..\FF.testsettings
    •  

       

      Note: Visual Studio 2008 uses runconfig instead of testsettings.

  25. To specify the output location for a results file, add:
    •  /resultsfile C:\Path\myResults.trx


    Normally MSTest creates the results in a uniquely named .trx file in a 'TestResults' folder. This folder is contained in the root of the project. For example: 'TestResults\agentuser_agent-pc4 2009-04-10 11_34_07.trx'. Because the name of this file is based on the logged on users ID & the machine's name, and the date & time, it can be hard for some continuous integration systems to find this results file, especially those that run MSTest via an 'exec' task. This option specifies the path and name of the results file to create. By specifying a fixed filename, it's easier for the continuous integration systems find the results file and pull it into the build report. The only drawback is that MSTest will fail (not even run tests) if the file specified already exists. Therefore you need to delete any results file that may have been left behind from previous builds. But be careful that your delete operation doesn't throw an error if the file to delete doesn't exist (for example, a simple 'del myResults.trx' will return an error if the file doesn't exist). This can cause some automated build systems to stop if it detects the error being returned by a simple delete operation.