【问题标题】:Loading data dynamically from properties file to jbehave story从属性文件动态加载数据到 jbehave 故事
【发布时间】:2014-05-04 23:56:24
【问题描述】:

如何将数据从 .properties 文件动态加载到我的 jBehave 故事文件中?我一直在我的故事文件中使用 $,例如:

When the stock is traded at price : $<price>
Then the alert status should be $<status>

我正在尝试从我的 src/test/resources 文件夹下的属性文件中获取值,并将我的 .properties 文件包含在 pom.xml 中,例如

    <testResource>
<directory>${basedir}/src/test/resources</directory>
<filtering>false</filtering>
<includes>
include>**/*.properties</include>
</includes>
    </testResource>

但它仍然无法正常工作。 当我尝试在我的 cmd 上运行“mvn integration-test”时。它抛出了这个异常

org.json.JSONException: A JSONObject text must begin with '{' at character 1
    at org.json.JSONTokener.syntaxError(JSONTokener.java:410)
    at org.json.JSONObject.<init>(JSONObject.java:179)
    at org.json.JSONObject.<init>(JSONObject.java:402)....

我不确定我哪里出错了。请帮帮我。 等待回复!! -测试员

【问题讨论】:

    标签: maven jbehave properties-file


    【解决方案1】:

    这些参数由示例语句提供。您可能对这部分很熟悉,但没有将其包含在您的示例故事中:

    When the stock is traded at price : <price>
    Then the alert status should be <status>
    Examples:
    |price|status|
    |10.00|low|
    |20.00|medium|
    |50.00|high|
    

    我不相信将 $ 与 结合使用是有效的。 我建议使用 而不是 $,因为后者在 JBehave 尝试查找匹配步骤时可能会模棱两可。

    但是,您可能不知道的是,上面故事的最后四行(示例和三个数据行)可以保存为文本文件,然后在故事中通过文件名引用,允许要动态更改的示例表。

    Examples:
    TableFiles/storystats.table
    

    也许这就是你要找的。​​p>

    【讨论】:

      猜你喜欢
      • 2019-12-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2011-05-02
      • 2012-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多