怎样在没有安装VS2010的环境里用mstest.exe跑test case?(注:以下实验在64位Windows 7上通过)
getmstest.bat
@echo off setlocal set here=%~dp0 mkdir mstest set targetfolder=%here%mstest set programs=%programfiles% if exist "%programfiles(x86)%" set programs=%programfiles(x86)% set vs2010="%programs%\Microsoft Visual Studio 10.0" set gac1="%windir%"\assembly set gac2="%windir%"\Microsoft.NET\assembly echo === Copying from Visual Studio 2010 install folder... copy %vs2010%\Common7\IDE\mstest* "%targetfolder%" copy %vs2010%\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Quality* "%targetfolder%" copy %vs2010%\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.CodedUITestFramework* "%targetfolder%" echo === Copying from %gac1%... pushd "%gac1%" dir /s /b *.dll | findstr QualityTools | findstr 10.0.0.0 > %here%tmp.filelist popd for /F "tokens=*" %%f in (tmp.filelist) DO copy "%%f" "%targetfolder%" echo === Copying from %gac2%... pushd "%gac2%" dir /s /b *.dll | findstr QualityTools | findstr 10.0.0.0 > %here%tmp.filelist popd for /F "tokens=*" %%f in (tmp.filelist) DO copy "%%f" "%targetfolder%" del tmp.filelist echo === Exporting registry keys... regedit.exe /e %targetfolder%\mstest.reg HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\EnterpriseTools\QualityTools\TestTypes echo === Done. Check output for errors! exit /b 0
2. 准备跑test case需要的文件:我把它们放在了C:\Users\username\Desktop\mstestCommandLine\test文件夹里,如下图所示。注意下图里的TestResults为自己新建的文件夹,run case时会用到,用于存储test result。现在,要准备的文件都放在了C:\Users\username\Desktop\mstestCommandLine里
3. 在目标机器上安装.NET Framework 4.0
4. 把C:\Users\username\Desktop\mstestCommandLine文件夹复制到目标机器上,假设复制到目标机器的桌面上
5. 在目标机器上,运行C:\Users\username\Desktop\mstestCommandLine\mstest这个文件夹里的mstest.reg(双击即可)
6.在目标机器上,Run->cmd, 回车,进入mstest.exe所在的文件夹,然后运行下面的命令:
mstest /noisolation /testcontainer:C:\Users\<username>\Desktop\mstest\test\TestProject1.dll /resultsfile:C:\Users\<username>\Desktop\mstest\test\TestResults\result.trx
7. 运行结果如下图所示:
参考: