简体   繁体   English

我如何在Java中为Fitnesse Fixture传递程序参数?

[英]how do i pass program arguments in java for my Fitnesse Fixture?

I have a fixture that needs some System arguments to be passed into it.How can i do the same. 我有一个灯具,需要将一些系统参数传递给它。我该怎么做。 ie java MyClass -Darg1=x -Darg2=y 即java MyClass -Darg1 = x -Darg2 = y

how do i pass the -Darg values into my test. 我如何将-Darg值传递到测试中。

@Dan. @担。 My Bad that I mentioned command line arguments.What I really intend to do is pass System properties as you pointed out.I have some settings like Region(NA/EMEA etc),Environment(SIT/UAT) etc based on which various urls etc differ.I have to compose tests in Fitnesse where I pass the values for the test screen from my decision table.But I want to be in a position to dictate that these tests should be run on so and so region/env combination.AT present I have a junit Test that triggers Selenium playback and I have control over its invocation from IDE/Maven by passing -Dregion etc.With Fitnesse I want to know how to pass these System arguments so that my Fixture when it gets invoked has access to these properties and it triggers playback of Selenium accordingly. 我提到命令行参数的缺点,我真正打算做的是传递您所指出的系统属性。我有一些设置,例如Region(NA / EMEA等),Environment(SIT / UAT)等,基于各种URL等我必须在Fitnesse中编写测试,并在其中通过决策表传递测试屏幕的值,但我希望能够指示这些测试应在区域/环境组合中进行。我有一个junit Test来触发Selenium播放,并且可以通过传递-Dregion等来控制它从IDE / Maven的调用.Fitnesse我想知道如何传递这些系统参数,以便我的灯具在被调用时可以访问这些参数属性,并相应地触发Selenium的播放。

To pass variables into FitNesse, you can set an environment variable. 要将变量传递到FitNesse,可以设置环境变量。 For example, start FitNesse from the command line like this: 例如,从命令行启动FitNesse,如下所示:

set SUT=www.google.de
java -jar fitnesse.jar -p 8080

You can use environment variables in FitNesse like other variables - '${SUT}' in a FitNesse test table will be replaced with www.google.de in the above example. 您可以像其他变量一样在FitNesse中使用环境变量-在上述示例中,FitNesse测试表中的'$ {SUT}'将替换为www.google.de。

Then to get the value of SUT into the test fixture, you can add a static class in the test fixture like this: 然后要将SUT的值添加到测试夹具中,可以在测试夹具中添加一个静态类,如下所示:

public class Environment {
    public static string SUT;
}

And somewhere in your FitNesse Setup code set the Environment SUT variable: 在您的FitNesse设置代码中的某处设置Environment SUT变量:

!|script|Environment|
|SUT|${SUT}|

Environment.SUT is then available throughout your Fixture code. 然后,在整个Fixture代码中都可以使用Environment.SUT。


Update: 更新:

Also see Dan's comment on how use Java System variables by starting fitNesse with the -D parameter. 另请参见Dan关于如何通过使用-D参数启动fitNesse来使用Java系统变量的评论。

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

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