我尝试使用一个名为testVar
的系统属性的不同值多次执行以下插件。我的pom.xml
中有以下插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<skip>false</skip>
<forkCount>1</forkCount>
<threadCount>3</threadCount>
</configuration>
<executions>
<execution>
<id>before-run</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<testVar>aaa</testVar>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>main-run</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<testVar>bbb</testVar>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
运行null
时得到System.getProperty("testVar")
。但是,当在插件级别声明testVar
时,我可以正确访问它。怎么了?
答案 0 :(得分:0)
您以错误的方式使用系统属性。您可以在下面查看如何使用它。
https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html
请看一个例子:
<systemPropertyVariables>
<!-- Appium's VM Variables -->
<target>${target}</target>
<mobile>${mobile}</mobile>
<deviceType>${deviceType}</deviceType>
</systemPropertyVariables>
不需要多个 systemPropertyVariables 标签。我不知道 execution 标签可以在maven surefire插件中使用。
现在用于访问系统属性。
System.getProperty("target");
System.getProperty("mobile");
System.getProperty("deviceType");
如何在Maven命令中使用
mvn test -Dtarget=Native -Dmobile=Android -DdeviceType=RealDevice
希望它能解决您的问题。
答案 1 :(得分:0)
在maven-surefire-plugin的配置中,您有几个export const login = (username,password) => {
return dispatch=>{
const basicAuth = 'Basic ' + btoa(username + ':' + password);
let myHeaders = new Headers();
myHeaders.append('Authorization', basicAuth);
myHeaders.append('Content-Type', 'application/json');
fetch(`${baseUrl}api/user/login`, {
withCredentials: true,
headers: myHeaders
})
.then(function (response) {
return response.json();
})
.then(function (json) {
dispatch(setLoginInfo(json))
})
.catch(err =>{
console.log(err)
dispatch(loginFailed())
});
}
}
标签,即目标execution
在默认阶段test
中执行了几次。实际上,您的插件配置会导致 3 测试执行:
test
与Maven 3.5.4:
mvn test
请考虑覆盖-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.example.app.ExampleTest
getProperty:null
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.078 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-surefire-plugin:2.14.1:test (before-run) @ app ---
[INFO] ...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.example.app.ExampleTest
getProperty:aaa
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.078 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-surefire-plugin:2.14.1:test (main-run) @ app ---
[INFO] ...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.example.app.ExampleTest
getProperty:bbb
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.078 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
执行,以正确应用您的配置。示例:
default-test