testify package provides
assert package and
require package. Some people only use
require whereas others intentionally mix
I thought I’m the one who care the difference, but Jacob pointed out that I wasn’t careful enough at that time;
nit: please prefer to use
assertif the tests allow it. Preferring
require, helps extract as many relevant failures in a single test run.
Yes! For sure :)
testify’s README explains the difference of the behaviors but doesn’t explain “why”. Instead it mentions;
See t.FailNow for details.
However, t.FailNow only says;
FailNow marks the function as having failed and stops its execution by calling runtime.Goexit (which then runs all deferred calls in the current goroutine). Execution will continue at the next test or benchmark. FailNow must be called from the goroutine running the test or benchmark function, not from other goroutines created during the test. Calling FailNow does not stop those other goroutines.
Yeah. But why does it provide
I think Google Test Primer is probably the best reference regarding “why”.
The assertions come in pairs that test the same thing but have different effects on the current function.
ASSERT_*versions generate fatal failures when they fail, and abort the current function.
EXPECT_*versions generate nonfatal failures, which don’t abort the current function. Usually
EXPECT_*are preferred, as they allow more than one failure to be reported in a test. However, you should use
ASSERT_*if it doesn’t make sense to continue when the assertion in question fails.
Unless it is coming from Plan 9, I think
FailNow() are coming from Google Test.