5

I have a CodedUiTest which has several test methods. I want to be able to pass a different path to the test each time I execute it from the command line via MSTest. How can I achieve this?

This is how I execute the test now:

{
    System.Diagnostics.Process codedUIProcess = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo codedUIStartInfo = new System.Diagnostics.ProcessStartInfo();

    codedUIStartInfo.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe";
    codedUIStartInfo.Arguments = @"/testcontainer:C:\DailyBuildAutoTest.dll /test:MyUITestAssembly\MyCodedUITest";
    codedUIStartInfo.CreateNoWindow = true;

    codedUIProcess.StartInfo = codedUIStartInfo;

    codedUIProcess.Start();
}

Is there any way to pass parameters like a string to "MyCodedUITest"?

4 Answers 4

1

No, unfortunately there is no way to do that. Check the MSTest Command-Line Options

The only possible way I can think is to associate the CodedUi Tests with the Test Cases and run them from Microsoft Test Manager.

Then you can easily parameterize the tests by adding parameters to test cases. These parameters are the DataSource of the associated test and you can read them from your CodedUi Test.

Sign up to request clarification or add additional context in comments.

3 Comments

Hm, manually executing the tests is not an option, unfortunately.
They are not executed manually. You can create Test Plan with several test cases. If the test cases have an assigned automated test then they will tun automatically. Check Running Automated Tests.
you can save your dependency in txt or csv format and put a logic to read them as a first part of test. we are following same manner to set environment variable of test.
1

Can you set an environment variable before invoking mstest and then use its value to generate the path string?

Comments

1

If you want to change the path of test container or mstest.exe you can use a bat file with the paths are arguments to the file and execute the bat file from a process.

 string _myBatchFile = "batFileFullPath;
 string _testContainer = "DllfileFullpath";
 string _testMethodName = "testMethodName";
 string _result = "resulFileName.trx";
 Process _process = new Process();

 _process.StartInfo.Arguments = string.Format("{0} {1} {2}", "\"" + _testContainer + "\"", _result, "\"" + _testMethodName + "\"");
                        _process.StartInfo.FileName = _myBatchFile;
                        _process.Start();
                        _process.WaitForExit();

Use quotation mark character before and after paths if they contains spaces between them. Otherwise it will be a problem to send them as argument to bat file.

Create a bat file like below to call it by the Process.

@ECHO on

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe" /testcontainer:%1 /test:%3 /resultsfile:%2

Comments

0

Yes. Right now there is no option in MSTest to pass parameter but there is work around which I have implemented in my project. Any parameter you need to pass that can be save in text file (or you can save in DB) and get the parameter value from text file when you execute the test case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.