---
# System prepended metadata

title: Golang 單元測試-指令

---

Golang 單元測試-指令

  

**產生測試結果及覆蓋率（txt）:**
```bash
go test ./... -coverprofile=coverage.out
go tool cover -func=coverage.out -o coverage.txt
```

**產生覆蓋結果（html）:**
```bash
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
```

**產生mock檔:**
```bash!
// internal
mockgen -source=./internal/account/account.go -destination=./internal/account/mock_account.go  -package=account

// mysql
mockgen -source=./repository/mysql/account.go -destination=./repository/mysql/mock_account.go -package=mysql
```