SpringBoot集成TestNG

增加dependency

1
2
3
4
5
6
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>

配置maven-surefire-plugin

1
2
3
4
5
6
7
8
9
10
11
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/test/resources/MyTestNG.xml</suiteXmlFile>
</suiteXmlFiles>
<!-- 不单独开线程启动test -->
<forkMode>never</forkMode>
</configuration>
</plugin>

增加MyTestNG.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite">
<test name="test1" verbose="2">
<classes>
<class name="com.springboot.testng.FirstTest">
<methods>
<include name="test"></include>
</methods>
</class>
</classes>
</test>
<test name="test2" verbose="2">
<groups>
<run>
<include name="testGroup"></include>
</run>
</groups>
</test>
</suite>

增加对应的类

注解

常用注解就那么几个,可以见下面的文章

https://blog.csdn.net/dragonpeng2008/article/details/70820902