简体   繁体   English

如何在查询字符串中设置Fitnesse变量

[英]How to set Fitnesse variables in query string

I'm currently setting up Fitnesse, with FitSharp and the .net implementation of dbfit. 我目前正在使用FitSharp和dbfit的.net实现来设置Fitnesse。

I understand how to trigger tests or suites from the submission of a URL, or from a command line, eg: 我了解如何通过提交URL或从命令行触发测试或套件,例如:

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. 因此,如果我有一个包含Sql语句的测试,该语句在Where子句中引用了Fitnesse变量,并且该变量的值在同级静态页面中定义,则我希望能够从命令行运行此测试并为此变量提交一个值,该值将覆盖静态页面中的值。 Something like: 就像是:

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

Is this possible at all? 这有可能吗?

Thanks Mark 谢谢马克

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). (1)定义一个环境变量(或识别一个已经存在的变量)。 You can use general purpose system variables (like %TMP% or %HOMEPATH% ) or your own user-defined variables (eg %JAVA_HOME% ) or create your own. 您可以使用通用系统变量(例如%TMP%%HOMEPATH% )或您自己的用户定义的变量(例如%JAVA_HOME% )或创建自己的变量。 My short Fitnesse launcher (a .CMD file) is this: 我的简短的Fitnesse启动器(.CMD文件)是这样的:

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. FITNESSE_PORT变量的定义仅用于下一行。 The SEED variable, however, does magic: it allows several people to run the same test simultaneously by generating unique values per session. 但是, SEED变量具有神奇的作用:它允许多个人通过在每个会话中生成唯一的值来同时运行相同的测试。 (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, eg (这假设每个用户都运行自己的FitNesse服务器,因此每个用户都有一个唯一的会话。)然后,我通过定义相对于种子的ID来测试我的测试,例如

!define TestClient (MyTestClient_${SEED})

(2) Pass an environment variable setting scoped to just the java process that instantiates the FitNesse runner. (2)传递一个环境变量设置,其范围仅限于实例化FitNesse运行程序的java进程。 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} . 这在FitNesse中产生的结果完全相同,使您可以将%SEED%环境变量访问为${SEED}

For more, see part 2 of my seven-part series on Acceptance Testing with FitNesse published on Simple-Talk.com. 有关更多信息,请参阅在Simple-Talk.com上发布的有关由FitNesse进行的验收测试的七部分系列文章的第2部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM