Documentation ¶
Overview ¶
reset package manage resettable operations useful for unit testing. Call reset.setEnabled(true) at begin of the test, call reset.setEnabled(false) at the end test.
All initialization code should register a reset function by reset.Add(), they will execute on .setEnabled(false). reset.Add() has no effect if reset module not enabled.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearInternal ¶
func ClearInternal()
ClearInternal used by reset package unit tests only, never call ClearInternal outside reset package
func Enabled ¶
func Enabled() bool
Return enabled state. Consider reset.Enabled() as test mode, if it is true, caller can sure she is running inside a unit test.
func Register ¶
func Register(fReset func(), fRecover func())
Register() register two function to cooperate testing reset/recover process. Unlike reset.Add(), which register a reset function to undo things for current call, after current test function finished. Register() normally register at package init() function to be part of testing cycle. Most reset.Add() can be replaced by Register().
Register() is better than Add():
- Better performance, when application runs in non-test mode, do not need over and over calling reset.Add().
- Add() not work well with static inited items, such as ert tree. Ert tree need reset itself to give a clean environment for next test. But unit test also depends on some pre-registered items in the ert tree, simply reset the whole ert tree can not work, fine control which ert entry need reset is too complex. Use Register() each package can re-register static ert items in the recover function.
fReset function called in ginkgo AfterEach() stage (actually in reset.Disable()), fReset function called in reversed register order. After all fReset() function called, fRecover() functions called by register order.
Both fReset and fRecover can be nil.
fRecover function run immediately on Register to do init job.
Types ¶
This section is empty.