一、IDEA配置Maven
1. 下载最新的maven包
URL: http://maven.apache.org/download.cgi
2. 解压maven到某目录(D:\server)
3. 配置Maven环境变量
M2_HOME:D:\server\apache-maven-3.5.0-bin\apache-maven-3.5.0
Path: D:\server\apache-maven-3.5.0-bin\apache-maven-3.5.0\bin
4. 新打开命令行工具,输入mvn -v回车,查看maven版本号信息
5. 打开IDEA,从菜单File->Settings...,然后在左侧选择到Maven配置项,如图所示:
二、IDEA+Maven+Testng配置
1. File -> New -> Project -> Maven -> Next, 填写GroupId和ArtifactId
2. 导入testng依赖包,在pom.xml文件中添加(依赖包版本路径查看方法,如:org.testng,查看路径:C:\Users\Ghome_ling\.m2\repository\org\testng\testng)
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgs>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation</arg>
<!--<arg>endorseddirs=${endorsed.dir}</arg>-->
</compilerArgs>
</configuration>
</plugin>
添加插件关联testNg.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<file>res/testNG.xml</file>
</suiteXmlFiles>
<!--<workingDirectory>target/</workingDirectory>-->
</configuration>
</plugin>
</plugins>
</build>
3. Testng测试
public classTestDemo {
@Test
public voidtestcase1(){
Assert.assertFalse(false);
System.out.println("testcase1");
}
@Test
public voidtestcase2(){
Assert.assertTrue(true);
System.out.println("testcase2");
}
@Test
public voidtestEmailGenerator(){
RandomEmailGeneratorobj = newRandomEmailGenerator();
Stringemail =obj.generate();
Assert.assertNotNull(email);
Assert.assertEquals(email,"xxx@qq.com");
}
}
运行结果: