Skip to content

Commit

Permalink
支持mvn test -Denv-name=api-config.xml 动态传配置文件名
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenSen5 committed Jul 2, 2017
1 parent 2731154 commit 66c31be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Expand Up @@ -10,6 +10,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<envName>api-config.xml</envName>
<xmlFileName>testng.xml</xmlFileName>
</properties>
<build>
Expand All @@ -19,6 +20,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<systemProperties>
<envName>${envName}</envName>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>${xmlFileName}</suiteXmlFile>
</suiteXmlFiles>
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/test/com/sen/api/ApiTest.java
Expand Up @@ -72,9 +72,10 @@ public class ApiTest extends TestBase {
*
* @throws Exception
*/
@Parameters("envName")
@BeforeSuite
public void init() throws Exception {
String configFilePath = Paths.get(System.getProperty("user.dir") , "api-config.xml").toString();
public void init(@Optional("api-config.xml") String envName) throws Exception {
String configFilePath = Paths.get(System.getProperty("user.dir"), envName).toString();
ReportUtil.log("api config path:" + configFilePath);
apiConfig = new ApiConfig(configFilePath);
// 获取基础数据
Expand Down Expand Up @@ -127,6 +128,7 @@ public Iterator<Object[]> getApiData(ITestContext context)

@Test(dataProvider = "apiDatas")
public void apiTest(ApiDataBean apiDataBean) throws Exception {
ReportUtil.log("--- test start ---");
if (apiDataBean.getSleep() > 0) {
// sleep休眠时间大于0的情况下进行暂停休眠
ReportUtil.log(String.format("sleep %s seconds",
Expand Down

0 comments on commit 66c31be

Please sign in to comment.