1

我的流程中有一些占位符。这些占位符的值在属性文件(在classpath中)中指定。我正在使用 java 做 munit。目前,这些占位符不会被属性文件中的值替换。知道如何在运行 munit 时加载此文件吗?

我的单元是这样的:

Class MyClass extends FunctionalMunitSuite{

    @Override
    protected String getConfigResources() {

        //try 1[gave give value pairs directly]: didnt worked
         System.getProperties().put("prop.key", "value");

         //try2[load prop files]:didn't worked
         prop.load(this.getClass().getResourceAsStream("mypropertyfile.properties"));
         System.setProperties(prop); 
    }

}
4

2 回答 2

2

在 Overriding中getConfigResources()指定一个test-config.xml具有您的模拟连接器和属性文件的上下文属性占位符。将该测试属性文件存储在 src/test/resources

@Override
    protected String getConfigResources() {
        return "mule-config-test.xml" + ",actual-flow-to-test.xml";
    }

在里面mule-config-test.xml,像这样定义测试属性文件:

<context:property-placeholder ignore-resource-not-found="true" location="wmo-mule-app.properties,wmo-mule-app-unit-test.properties" />

在这种情况下,wmo-mule-app.properties我的实际应用程序属性文件wmo-mule-app-unit-test.properties是覆盖单元测试属性文件。此单元测试属性文件将优先于wmo-mule-app.properties

于 2016-05-05T17:10:15.317 回答
0

当前,您可能将文件放在/src/main/resources 尝试将其放入/src/test/resources

于 2016-05-05T10:34:42.080 回答