标签:替换 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,结果为
标签:替换 rtt exp img stand width class not sts
原文地址:https://www.cnblogs.com/csj2018/p/9195276.html