使用Mock,我們可以精確斷言某方法以特定參數(shù)的調(diào)用次數(shù),Times(n int),它有兩個(gè)便捷函數(shù)Once()/Twice()。下面我們要求函數(shù)Hello(n int)要以參數(shù) 1 調(diào)用 1次,參數(shù) 2 調(diào)用兩次,參數(shù) 3 調(diào)用 3 次: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 type IExample interface { Hello(n int) int } type...
www.dbjr.com.cn/article/2565...htm 2025-5-27