spring-boot 整合junit测试类 和 spring-boot整合整合testng

一、spring-boot 整合junit测试类

1.引入junit依赖

<!-- springboot junit依赖 -->
		<dependency>
	  		<groupId>org.springframework.boot</groupId>
	       <artifactId>spring-boot-starter-test</artifactId>
	  	</dependency>

2.编写测试类

package com.jiayun.service;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.jiayun.App;

@RunWith(SpringJUnit4ClassRunner.class) // jar包中的类
@SpringBootTest(classes={App.class})// 指定spring-boot的启动类
public class UserServiceTest {
	
	@Autowired
	private UserService userService;
	
	@Test
	public void testInsertUser(){
		userService.insertUser();
	}

}

3.junit运行

链接:https://pan.baidu.com/s/1n8MO-8rNB91gjzbQXbuwLg 
提取码:o5z2 
复制这段内容后打开百度网盘手机App,操作更方便哦

 

二、spring-boot 整合testng测试

1.eclipse需要安装testng插件,eclipse两种直接安装的方法都不靠谱,反正我没装上。

用eclipse离线安装插件的方法

https://blog.csdn.net/hualf/article/details/78507274   验证OK

2.跟junit差不多的写测试方法就行了

https://blog.csdn.net/m0_37696252/article/details/82629168

对了,需要引入testng的依赖

<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<scope>test</scope>
		</dependency>
			<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>6.8.13</version>
			<scope>test</scope>
		</dependency>

testng单元测试控制台输出中午编码有问题,解决方法

https://blog.csdn.net/jjj0817/article/details/70888732

在eclipse根目录下打开eclipse.ini文件,增加-Dfile.encoding=UTF-8 这一句话 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值