I always thought that good unit test, are test that are independent. By 'independent' i mean that when function 'A' uses 'B', and we test function 'A', we mock/stub out 'B' in case when 'B' does not work correctly it will not fail 'A'.
But when we check sources of golang packages that principle is not respected.
For example lets check url.go and url_test.go in url packages:
url.go:
func parseQuery(m Values, query string) (err error) {
for query != "" {
...
key, err1 := QueryUnescape(key)
...
url_test.go:
func TestParseQuery(t *testing.T) {
for i, test := range parseTests {
form, err := ParseQuery(test.query)
...
As we can see parseQuery
use QueryUnescape
. In test QueryUnescape
is not stubbed in any way. So if QueryUnescape
will work wrong, parseQuery
test will fail.
So authors of package not always meet requirement of 'independent' unit test. What was the reason to not bother about this principle in this case, is there some rule that allow programmer of accepting this form of unit tests?
After writing independent test in python, I'am little confused about balancing between writing perfect test(which much affects in golang about design of code) and results.