(三)Java版接口自动化-testNG测试框架的使用与介绍
一、TestNG介绍
TestNG是Java中的一个测试框架, 类似于JUnit 和NUnit, 功能都差不多, 只是功能更加强大,使用也更方便
Java中已经有一个JUnit的测试框架了。 TestNG比JUnit功能强大的多。 测试人员一般用TestNG来写自动化测试。 开发人员一般用JUnit写单元测试。
官方网站: http://testng.org/doc/index.html
二、TestNG的使用
1、在pom.xml中引入包
<dependency> <groupId>org.testnggroupId> <artifactId>testngartifactId> <version>6.10version> dependency>
2、常用方法测试
package com.automation.interfacetest; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** * @title: * @author: 2022/1/1113:52 * @date: 2022/1/1113:52 */ public class TestCase { @BeforeClass public void testBefore() throws Exception{ System.out.println("this is before class"); } @Test public void test002() throws Exception{ System.out.println("this is TestNG test case"); } @AfterClass public void testAfter() throws Exception{ System.out.println("this is after class"); } }
3、使用testng.xml文件执行用例
<?xml version="1.0" encoding="UTF-8"?>DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="MySute"> <test name="TestCaseClass"> <classes> <class name="com.automation.interfacetest.TestCase"> class> classes> test> suite>
4、运行结果