我如何在java中为我的Fitnesse Fixture传递程序参数? [英] how do i pass program arguments in java for my Fitnesse Fixture?

查看:96
本文介绍了我如何在java中为我的Fitnesse Fixture传递程序参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要将一些System参数传递给它的fixture。我怎么能这样做。
即java MyClass -Darg1 = x -Darg2 = y

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

如何将-Darg值传递给我的测试。

how do i pass the -Darg values into my test.

@Dan。我的错,我提到了命令行参数。我真正打算做的是按照你指出的方式传递系统属性。我有一些设置,如Region(NA / EMEA等),Environment(SIT / UAT)等基于各种url等我必须在Fitnesse中进行测试,在那里我从决策表中传递测试屏幕的值。但是我想能够决定这些测试应该在某种区域/ env组合上运行。我有一个junit Test触发Selenium播放,我通过传递-Dregion等来控制它从IDE / Maven的调用。我和Fitnesse想知道如何传递这些System参数,以便我的Fixture在被调用时可以访问这些属性并相应地触发Selenium的回放。

@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.

推荐答案

要将变量传递给FitNesse,您可以设置环境变量。例如,从命令行启动FitNesse,如下所示:

To pass variables into FitNesse, you can set an environment variable. For example, start FitNesse from the command line like this:

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

您可以在FitNesse中使用环境变量,就像其他变量一样 - '$ {在上面的示例中,FitNesse测试表中的SUT}'将替换为www.google.de。

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.

然后将SUT的值放入测试夹具中,可以在测试夹具中添加一个静态类,如下所示:

Then to get the value of SUT into the test fixture, you can add a static class in the test fixture like this:

public class Environment {
    public static string SUT;
}

在FitNesse设置代码中的某处设置环境SUT变量:

And somewhere in your FitNesse Setup code set the Environment SUT variable:

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

然后,您可以在整个Fixture代码中使用Environment.SUT。

Environment.SUT is then available throughout your Fixture code.

另请参阅Dan关于如何使用-D启动fitNesse来使用Java系统变量的评论参数。

Also see Dan's comment on how use Java System variables by starting fitNesse with the -D parameter.

这篇关于我如何在java中为我的Fitnesse Fixture传递程序参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆