How to run Coded UI test file from Visual Studio c

2019-05-28 18:13发布

问题:

@echo off
@setlocal enableextensions
@cd /d "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE"
start %comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat""
MSTest /testcontainer:C:\testdir\test.dll

Code shown above runs vs command prompt and changes directory to "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE" where MSTest.exe is. But last line doesn't run in vs command prompt window, opens new window and tries to run in a new opened window. Can anyone help how to run ui test file in opened vs command prompt using batch file?

回答1:

I run my Coded UI tests with the following batch script:

@echo off
:: Running tests without VS Enterprise is possible if you install the Test Agent package: https://msdn.microsoft.com/en-us/library/dd648127.aspx

set test_runner="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
set test_dlls="C:\Location\Compiled\Tests\Project.CodedUI.Test.dll"

:: If tests is set then only these comma separate test cases are run
:: set tests="Test1,Test2"
set tests=""

if %tests% == "" (
     %test_runner% %test_dlls% > CodedUITestResults.txt
) else (
     %test_runner% %test_dlls% /tests:%tests%
)
pause

The visual studio number should be replaced per different version

  • VS2015: 14.0
  • VS2013: 12.0
  • Etc