First, the environment configuration
1, the installation IDEA (Reference: https://blog.csdn.net/m0_38075425/article/details/80883078 )
2, in Prefernces, mounting TestNG-J (IDEA automatically integrate new plug-in) by plug Plugins
3, test items, introduced jar package (Add-dependent)
Two ways
1, the following code is directly introduced in pom.xml, IDEA will automatically download dependencies
<dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.10</version> //版本号可以根据需要修改 <scope>compile</scope> </dependency> </dependencies>
2, in the Project Structure, click +, select maven project, search TestNG, import jar package (this search method is slow ...)
(Refer https://blog.csdn.net/u010270891/article/details/82978260 )
Second, write code
TestNG基本用法参考:https://blog.csdn.net/duanlei123456/article/details/87454737
可以直接引用TestNG注解,以下是我的测试demo
package com.cat; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class Test01 { @BeforeClass public void beforeClass(){ System.out.println("beforeClase"); } @AfterClass public void afterClass(){ System.out.println("afterClass"); } @Test public void testcase1(){ Assert.assertEquals(1,1); System.out.println("test01"); } @Test public void testcase2(){ Assert.assertTrue(true); System.out.println("test02"); } @DataProvider(name="user") public Object[][] getStr(){ return new Object[][]{ {"","","账户不能为空"}, {"admin","","密码不能为空"}, {"admin","123","密码错误"} }; } @Test(dataProvider = "user") private void sout(String uname,String pword,String msg){ System.out.println(uname+"->"+pword+"->"+msg); } }