如何测试doStuff功能?(游乐场:http : //play.golang.org/p/aPFSlaBLgX)
package myPackage
var locked = false
func doStuff() {
defer unlock()
lock()
// some task that can cause errors
// need to test if lock was really unlocked
// this is just a simple example, things can go complex on real world
panic("!")
}
func lock() {
locked = true
}
func unlock() {
locked = false
}
换句话说:如何测试使用defer语句的代码?应该使用哪些一般策略来测试延迟调用?如果没有通用的做法,如何测试这个具体的代码?
PS:去游乐场只允许 package main
慕雪6442864
相关分类