【问题标题】:Running test with propery file filtered by maven使用 maven 过滤的属性文件运行测试
【发布时间】:2013-10-16 15:09:11
【问题描述】:

我希望能够在一些最近被 Java 测试使用的属性文件中配置值。 这是我的 pom.xml

<profiles>
        <profile>
            <id>env-dev</id>
            <activation>
                <property>
                    <name>env</name>
                    <value>dev</value>
                </property>
            </activation>
            <properties>
                <target.env>http://myurl.com</target.env>
            </properties>
        </profile>
    </profiles>
    <build>
        <resources>
            <resource>
                <directory>src/test/java</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>

属性文件

targetEnv=${target.env}

当我运行mvn install -Denv=dev 时,我可以看到在目标文件夹中,属性文件正在获取正确的值,但在测试期间,占位符被用于我想在测试运行时使用实际值的地方。

我做错了什么?

谢谢

【问题讨论】:

    标签: java maven testng


    【解决方案1】:

    我做错了什么?

    首先,不要使用配置文件在环境之间切换。特别是单元测试不应该知道任何环境设置。在这种情况下请删除它。 要过滤测试资源,您应该改用&lt;testResources/&gt;-tag。

    【讨论】:

      猜你喜欢
      • 2017-07-09
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      相关资源
      最近更新 更多