1
我希望能夠在Java測試最近使用的某些屬性文件中配置值。 這裏是我的pom.xml用maven過濾的propery文件運行測試
<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
我可以看到目標文件夾中,該屬性文件獲得正確的值,但在測試過程中的佔位符在測試運行時使用我想要使用真實值的地方。
我在做什麼錯?
感謝