How to set Fitnesse variables in query string

1.5k views Asked by At

I'm currently setting up Fitnesse, with FitSharp and the .net implementation of dbfit.

I understand how to trigger tests or suites from the submission of a URL, or from a command line, eg:

java -jar fitnesse-standalone.jar -c "MyTest?test&format=text"

What I can't figure out is how to submit variable values in this query string.

So, if I have a test containing a Sql statement which has a Fitnesse variable referenced in the Where clause, and the value of this variable is defined in a sibling static page, I would like to be able to run this test from the command line and submit a value for this variable which overrides the value in the static page. Something like:

java -jar fitnesse-standalone.jar -c "MyTest?test&format=text&${myVar}=abc"

Is this possible at all?

Thanks Mark

1

There are 1 answers

0
Michael Sorens On

There are two ways to pass variables from the command line, both involving environment variables.

(1) Define an environment variable (or identify one that already exists). You can use general purpose system variables (like %TMP% or %HOMEPATH%) or your own user-defined variables (e.g. %JAVA_HOME%) or create your own. My short Fitnesse launcher (a .CMD file) is this:

set SEED=%RANDOM%
set FITNESSE_PORT=9999
java -jar fitnesse-standalone.jar -p %FITNESSE_PORT% -e 0

The FITNESSE_PORT variable is defined just for use in the very next line. The SEED variable, however, does magic: it allows several people to run the same test simultaneously by generating unique values per session. (This assumes that each user runs their own FitNesse server, so each will thereby have a unique session.) I then instrument my tests by defining ids relative to the seed, e.g.

!define TestClient (MyTestClient_${SEED})

(2) Pass an environment variable setting scoped to just the java process that instantiates the FitNesse runner. This technique gives you precisely the same results with just a different implementation:

java -DSEED=%RANDOM% -jar fitnesse-standalone.jar -p %FITNESSE_PORT% -e 0

This yields precisely the same result within FitNesse, giving you access to the %SEED% environment variable as ${SEED}.

For more, see part 2 of my seven-part series on Acceptance Testing with FitNesse published on Simple-Talk.com.