Friday, July 8, 2011

One click start

Actually the tests run without any clicks, but just at appointed time, but there should be some command file to begin. Fortunately, it's easy with SpecFlow. Assume, the VS2010 SpecFlow with Coded UI Test is ready, if not see http://ixkormachev-sf-and-cui.blogspot.com. Then there is the batch file to start it:

test_runner.bat:
:: @ECHO OFF

:: If you want, you can start some additional application to provide the environment
::start cmd.exe /C add_app1_start.bat
::sleep 2
::start cmd.exe /C add_app2_start.bat
::sleep 80
::start cmd.exe /C add_app3_start.bat

Mstest /testcontainer:bin/Debug/SpecFlowTest.dll /test:TestName1
Mstest /testcontainer:bin/Debug/SpecFlowTest.dll /test:TestName2
Mstest /testcontainer:bin/Debug/SpecFlowTest.dll /test:TestName3
Mstest /testcontainer:bin/Debug/SpecFlowTest.dll /test:TestName4
Mstest /testcontainer:bin/Debug/SpecFlowTest.dll /test:TestName5
Mstest /testcontainer:bin/Debug/SpecFlowTest.dll /test:TestName6
Mstest /testcontainer:bin/Debug/SpecFlowTest.dll /test:TestName7

:: Stop additional applications, if needed
::TASKKILL /F /IM add_app1.exe
::sleep 2
::TASKKILL /F /IM add_app2.exe
::sleep 2
::TASKKILL /F /IM add_app3.exe

It's easy, isn't it? But test_runner.bat should be run in the VS2010 console, so to start it we run the following batch file:

test_automation.bat
c:
cd \
cd path_to\SpecFlowTest
cmd.exe /k "call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" & test_runner.bat"

That's all. Just place a shortcut for test_automation.bat to desktop or to some scheduler, and you can get what you want. Of course, the necessary error handling and log handling should be added according to your needs.