Forum Discussion

djangofan's avatar
djangofan
Contributor
12 years ago

Improved testrunner.bat script

I wrote an improved testrunner.bat script. It would be nice if you could consider adding it to the next release. It should be backwards compatible and so there should be no problems upgrading it.



@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
:: Author Jon Austen, May 2013

TITLE Script %~n0%~x0 running from %~dp0

CALL :getparentfolder bin

IF EXIST "%SOAPUI_HOME%\jre\bin" (
ECHO Using embedded version of Java at ^"%SOAPUI_HOME%\jre\bin\java.exe^".
SET JAVA=%SOAPUI_HOME%\jre\bin\java.exe
) ELSE (
IF NOT DEFINED JAVA_HOME (
ECHO JAVA_HOME is not set, unexpected results may occur with %~n0%~x0 .
ECHO Set JAVA_HOME to the directory of your local JDK to avoid this message.
SET JAVA=java.exe
) ELSE (
ECHO Using Java defined by JAVA_HOME.
SET JAVA=%JAVA_HOME%\bin\java.exe
)
)
ECHO.

:: initialize classpath var with optional PRE_CLASSPATH var prepended
:: testcaserunner class will auto load CLASSPATH without need to pass as -cp arg
IF NOT DEFINED CLASSPATH SET CLASSPATH=.
IF DEFINED PRE_CLASSPATH set CLASSPATH=%PRE_CLASSPATH%;%CLASSPATH%
SET CLASSPATH=%CLASSPATH%;%SOAPUI_HOME%\bin\soapui-4.5.1.jar;%SOAPUI_HOME%\lib\*

:: JVM parameters, modify as appropriate
SET JAVA_OPTS=-Xms128m -Xmx1024m -Dsoapui.properties=soapui.properties "-Dsoapui.home=%SOAPUI_HOME%\bin"
SET JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.libraries="%SOAPUI_HOME%\bin\ext"
SET JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.listeners="%SOAPUI_HOME%\bin\listeners"
SET JAVA_OPTS=%JAVA_OPTS% -Dsoapui.ext.actions="%SOAPUI_HOME%\bin\actions"

:START
ECHO ::::::::::::::::::::::::::::::::::::::::
ECHO :: Running soapui testcase runner...
ECHO :: Implicit classpath: %CLASSPATH%
ECHO ::::::::::::::::::::::::::::::::::::::::
ECHO.
"%JAVA%" %JAVA_OPTS% com.eviware.soapui.tools.SoapUITestCaseRunner %*

GOTO :END

:: function to get parent folder name of scripts currrent folder
:: function requires current folders name as an arg or it will fail to run
:getparentfolder dirName
SET "BIN_HOME=%~dp0"
IF "%BIN_HOME:~-1%"=="\" SET "BIN_HOME=%BIN_HOME:~0,-1%"
ECHO Current directory is: %BIN_HOME%
FOR /F "delims=" %%I IN ("%BIN_HOME%") DO (
SET THISFOLDER=%%~nI
)
ECHO This folder name is ^"%THISFOLDER%^".
IF "%~1"=="%THISFOLDER%" (
SET SOAPUI_HOME=!BIN_HOME:\%THISFOLDER%=!
ECHO SOAPUI_HOME: %SOAPUI_HOME%
) ELSE (
ECHO Function arg ^"%~1^" must match actual folder name.
ECHO This script may not be running from the expected folder.
GOTO :ERROR
)
EXIT /B 0

:ERROR
ECHO There was an error in %~n0%~x0
PING.exe -n 10 -w 1 127.0.0.1>nul
:END
ECHO The script %~n0%~x0 is finished.


NOTE-1: I added a PRE_CLASSPATH var. I don't think that would tempt people to place jdbc .jar files outside of the recommended 'ext' location, but if you think it would, then I understand.

NOTE-2: The latest version of this script can be found in my blog post (below).