Closed cored closed 6 years ago
@danielfireman I'm following same patterns in the codebase, however, there are some things that I don't quite understand. Why is it that the test does assertions against private functions? Wouldn't be better to use schema_test
package for the tests and just test public functions?. If the reason is that these functions support a higher level component why not just add the test at that level?
Hi @cored, thanks for your contributions!
About your question:
@danielfireman I'm following same patterns in the codebase, however, there are some things that I don't quite understand. Why is it that the test does assertions against private functions? Wouldn't be better to use schema_test package for the tests and just test public functions?. If the reason is that these functions support a higher level component why not just add the test at that level?
As the code gets more complex, it is usually better to rely more heavily on unit testing. There are many reasons for that, including easier maintenance, faster, simpler (more benefits here).
Let's say we decide to test that against the public Field.Decode. That simple test would involve: i) creating a field as a string, ii) call json.Unmarshal
and iii) either check error or success. That still quite simple, but I its much simpler to assume the Field struct knows how to perform steps i and ii and check the third step as a unit.
for issue #44