TestNG环境配置

一、IDEA配置Maven

1. 下载最新的maven

URL: http://maven.apache.org/download.cgi



2. 解压maven到某目录(D:\server

 

3. 配置Maven环境变量

M2_HOMED:\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, 填写GroupIdArtifactId

 

 

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");
    }
}

 

运行结果:


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值