码迷,mamicode.com
首页 > 其他好文 > 详细

导入testng管理测试用例

时间:2018-06-18 16:05:29      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:替换   rtt   exp   img   stand   width   class   not   sts   

1.在pom.xml中增加testng的依赖,以导入testNG

2.在src-main-resources目录下新建xml文件,比如untitled.xml.

技术分享图片

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testSuite1">
<test name="UITest">
<classes>
<class name="testcase.TestNG" />
<class name="testcase.testNG2" />
<class name="testcase.testNG1" />
</classes>

</test>
</suite>

3.BeforeTest AfterTest BeforeClass AfterClass的区别

 BeforeTest AfterTest

case1:

package testcase;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class testNG3 {
@BeforeTest
public void setup(){System.out.println("case3:set up");}
@Test
public void test1(){System.out.println("case3");}
@AfterTest
public void tearup(){System.out.println("case3:tear down");}
}

case2:

package testcase;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class testNG4 {
@BeforeTest
public void setup(){System.out.println("case4:set up");}
@Test
public void test1(){System.out.println("case4");}
@AfterTest
public void tearup(){System.out.println("case4:tear down");}
}

xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testSuite1">
<test name="UITest">
<classes>
<!--<class name="testcase.TestNG" />
<class name="testcase.testNG2" />
<class name="testcase.testNG1" />-->
<class name="testcase.testNG3"/>
<class name="testcase.testNG4"/>
</classes>

</test>
</suite>
执行结果:

技术分享图片

将BeforeTest替换为BeforeClass,AfterTest替换为AfterClass

case1:

package testcase;

import org.testng.annotations.*;

public class testNG3 {
@BeforeClass
public void setup(){System.out.println("case3:set up");}
@Test
public void test1(){System.out.println("case3");}
@AfterClass
public void tearup(){System.out.println("case3:tear down");}
}

case2:

package testcase;

import org.testng.annotations.*;

public class testNG4 {
@BeforeClass
public void setup(){System.out.println("case4:set up");}
@Test
public void test1(){System.out.println("case4");}
@AfterClass
public void tearup(){System.out.println("case4:tear down");}
}

xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testSuite1">
<test name="UITest">
<classes>
<!--<class name="testcase.TestNG" />
<class name="testcase.testNG2" />
<class name="testcase.testNG1" />-->
<class name="testcase.testNG3"/>
<class name="testcase.testNG4"/>
</classes>

</test>
</suite>

执行结果:

技术分享图片

4.使用TestNg增加断言

package testcase;
import org.testng.Assert;
import org.testng.annotations.*;
public class testNG3 {
@BeforeClass
public void setup(){System.out.println("case3:set up");}
@Test
public void test1(){
System.out.println("case3");
String actureMessage="abc";
String expectMessage="efg";
Assert.assertTrue(actureMessage.equalsIgnoreCase(expectMessage),"Expect message is "+expectMessage+".But acture message is "+actureMessage);
}
@AfterClass
public void tearup(){System.out.println("case3:tear down");}
}

技术分享图片

将expectMessage修改为abc,结果为


技术分享图片

 

 


  

导入testng管理测试用例

标签:替换   rtt   exp   img   stand   width   class   not   sts   

原文地址:https://www.cnblogs.com/csj2018/p/9195276.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!