Skip to content

Commit 2d47dd7

Browse files
lvan100lianghuan
authored andcommitted
update README.md
1 parent 086e413 commit 2d47dd7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

README_CN.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,11 @@ func init() {
536536

537537
## ⏳ Mock 与单元测试
538538

539-
Go-Spring 提供了和 go test 无缝集成的单元测试框架。
540-
你可以使用 `gstest.MockFor[T]().With(obj)` 在运行时替换掉一个 bean。
541-
你可以使用 `gstest.Wire(t, ...)` 或者 `gstest.Get[T](t)` 获取对象实例。
539+
Go-Spring 提供了与标准 `go test` 无缝集成的单元测试框架,让依赖注入和模拟测试变得简单高效。
540+
541+
### 1. 模拟对象注入
542+
543+
使用 `gstest.MockFor[T]().With(obj)` 可以在运行时轻松替换任何 bean:
542544

543545
```go
544546
gstest.MockFor[*book_dao.BookDao]().With(&book_dao.BookDao{
@@ -553,11 +555,19 @@ gstest.MockFor[*book_dao.BookDao]().With(&book_dao.BookDao{
553555
})
554556
```
555557

558+
### 2. 获取测试对象
559+
560+
有两种方式获取被测试对象:
561+
562+
**直接获取实例**
563+
556564
```go
557565
o := gstest.Get[*BookDao](t)
558566
assert.NotNil(t, o)
559567
```
560568

569+
**结构化注入**
570+
561571
```go
562572
s := gstest.Wire(t, new(struct {
563573
SvrAddr string `value:"${server.addr}"`

0 commit comments

Comments
 (0)