A programmed test can be executed through command line program MSTest.exe. Windows Task scheduler can be used to schedule the MSTest.exe to run at particular time or in particular period to allow scheduling the automated tests. This piece of writing provides overview of MSTest.exe which is offered as part of Visual Studio or Test Agent installations and Windows Task Scheduler which is component of various Windows operating systems.
MSTest.exe is the command-line command that is used to run tests. This command has a number of options which can be used to tailor the test run. MSTest.exe does neither interpret the options nor the values specified for them in a case-sensitive way. MSTest.exe program can be used to run automated tests in a test assembly from a command line. It is also feasible to view the test results from these test runs, save the outcome to disk, and save results to Team Foundation Server. See How to: Run Automated Tests from the Command Line Using MSTest for additional information on the same. Below is a snapshot displaying a small amount of of the command-line options that can be used to modify the run. Refer MSTest.exe Command-Line Options for entire list.
Task scheduler is a Windows component that provides the facility to schedule the initiation of programs or scripts at pre-defined times or after specified time intervals. The Windows Event Log service must be running before the Task Scheduler starts up. The Task Scheduler service works by managing tasks; Task refers to an action taken in response to trigger. A task is defined by associating a set of events, which can include launching an application, executing a command or taking some custom-defined action, to a set of triggers, which can either, be time-based or event-based. See How To Schedule Tasks in Windows XP for more information on the same. Similar information can be found for diverse operating systems. The picture below gives summary of screens and available options to schedule a task using Windows Task Scheduler in Windows XP operating system.
From the information available in above sections, it is possible to schedule any automated test by creating a parameterized command of MSTest.exe to execute that test with required customization and scheduling that command with the help of Windows Task Scheduler. For the ease of managing the complex commands that have multiple lengthy parameters, it is good to use a batch file to execute that command. Batch file is type of a script, a text file that contains one or more commands to be executed. Thus we can manage the MSTest.exe command and its parameters separately from the task that is created in Windows Task Scheduler.
This batch file should have command that shall be executed to run an automated test. The command will be somewhat similar to shown below. It has placeholders for required and commonly used parameters to help user create the command. The command doesn’t contain actual parameters and hence they must be replaced with actual values. The parameters which are not used should be removed or MSTEST.EXE may throw invalid argument error! The output of this command will be saved in a .log file created with date time to see in case of issues.
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" /testcontainer:[.dll/.loadtest/.webtest] /testsettings:[.testsettings] [/test:[TestMethod names] multiple times] [/testmetadata:.vsmdi file] [/testlist:[testlists] multipletimes]>> %date:~-4,4%-%date:~-7,2%-%date:~-10,2%_%time:~0,2%.%time:~3,2%.%time:~6,2%.log
Below is short description of the parameters provided and the usage:
Parameter Name
Used to specify
Comments
Testsettings
To use the specified test settings file for test run. (provide .testsettings file)
Testcontainer
Load a file that contains tests. Provide .dll (for Coded UI), .webtest or .loadtest file.
Multiple files can be provided.
Test
The name of a test to be run.
Multiple tests can be provided.
Use with TestContainer to run only selected tests in case .dll is provided that contains multiple tests.
Testmetadata
Load a file that contains test metadata (for .vsmdi file)
Do not use this option along with TestContainer.
testlist
The name of the test list to be run (as specified in metadata file)
Multiple lists can be provided.
Use with TestMetadata to run selected tests using test list in case .dll is provided that contains multiple tests.
Since the resultfile parameter is not provided in the command, the results will be generated inside TestResults directory inside the path where batch file is executed (Start in path of the task). This is a better option compared to giving explicit result file because the result file may get overwritten if same test runs multiple times.
This is a task configured to run at desired time or with available triggers. Below is a table explaining the parameters to be set or changed in the task:
Tab / Section
Field
Task
Run
Path of the file to be run as scheduled task
Give the full path of the batch file here
Start in
Path of the folder where file/program is located
Give path of the folder that contains the batch file
Run as
User account details that runs the scheduled tasks
Give valid user name password that has access to schedule tests
Schedule
Schedule Task
How often the task should run
Select Once/ Daily/ Weekly as required
Start Time
Time when scheduled task should start
Advanced Options
Additional Scheduling options such as dates
Schedule/ Advanced
Repeat Task
Specify to repeat task at interval specified
Use for executing task multiple times
Richard Mueller edited Revision 10. Comment: Remove tag "MSTEST. mstest.exe"
Richard Mueller edited Revision 9. Comment: Removed tags "Microsoft Visual Studio 2010" and "MS", change tag "VS 2010" to "Visual Studio 2010"
Richard Mueller edited Revision 8. Comment: Remove blank headings from HTML to fix TOC
Ed Price - MSFT edited Revision 7. Comment: Title casing and added tags
TejasJ edited Revision 2. Comment: added links
TejasJ edited Revision 1. Comment: Broken links modified.
TejasJ edited Original. Comment: Repair table formatting.