3 ms·
It becomes painful to write in unit tests. I really liked their `check` proposal. I hope they will bring it back to life.
by iambvk 5y ago
It becomes painful to write in unit tests.
I really liked their `check` proposal. I hope they will bring it back to life.
- politician 5y agoDo you use stretchr/testify/assert? I find that it makes error handling in tests as natural as assertions on other properties.
- benhoyt 5y agoAside from the "assertion" libraries, which I have mixed feelings about, I often use table-driven tests to avoid this. That way each test is generally one line, like `{"1234", 1234}` for testing an Atoi function. Or, I've seen little test helper functions that "fatal" the test on error -- that way it only takes one line instead of three: https://play.golang.org/p/WIALie5fsgd https://play.golang.org/p/WIALie5fsgd
- simiones 5y agoThe thing I hate about table-driven tests is that they make it slightly harder to identify where an error has occurred, and much harder to debug the specific test case that triggered the error, especially in Go where dlv lacks value breakpoints (or it did last time I checked - if they've added that in the meantime, this becomes much less of a problem).