mirror of
https://github.com/Estom/notes.git
synced 2026-05-12 03:26:37 +08:00
简单整理了java部分的笔记
This commit is contained in:
13
Junit/概述.md
Normal file
13
Junit/概述.md
Normal file
@@ -0,0 +1,13 @@
|
||||
## 概述
|
||||
|
||||
|
||||
|
||||
## 关键点
|
||||
|
||||
|
||||
1. 导入Springboot相关的依赖,spring-boot-starter
|
||||
2. 写测试类,添加@SpringbootTest。该注解能够增加Spring的上下文,及@Autowire进行bean的注入。
|
||||
3. 写测试方法,添加@Test注解,填写测试用例。通过Assertions方法,进行断言。
|
||||
4. @BeforeEach、@BeforeAll、@AfterEach、@AfterAll。能够在不同阶段执行相关的操作。
|
||||
5. 通过MockBean添加mock规则。使用when().thenReturn()方法进行mock掉一个bean的所有方法。可以在@BeforeEach中执行mock方法,或者@BeforeAll中执行。没配置的规则,返回默认值。
|
||||
6. 通过Spybean进行部分注Mock。首先注入bean,只mock配置规则的部分,没有配置规则的部分使用原来的方法。
|
||||
Reference in New Issue
Block a user