次のように行います
1)あなたのSCR /テスト/ resoucesでがtestConfig.propertiesを置く:
url = ${url}
2)は、テストを書く:
@Test
public void test() throws Exception{
String urlParam = null;
try {
Properties prop = new Properties();
InputStream input = null;
input = getClass().getClassLoader().getResourceAsStream("testConfig.properties");
prop.load(input);
urlParam = prop.getProperty("url");
}catch (Exception e){}
// use urkParam
}
3)をpom.xmlに追加する:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
4)実行達人、次のように:
mvn clean test resources:testResources -Durl=www.google.com
は今、あなたはMavenのPARAMに基づいてパラメータ化されたURLを取得します。
私はテストを実行しようとするとエラーが発生します [link](http://www.interload.co.il/upload/5985310.png) –
okあなたのテストメソッドとmvnコマンド..とあなたのプロパティファイルの内容 –
テストで不運?これは、おそらくあなたがおそらくいくつかの細部を見逃している可能性があります –