tendermint / coding

14 stars 10 forks source link

When to use `package X_test` #4

Closed ebuchman closed 6 years ago

ebuchman commented 7 years ago

package X_test forces you to do testing through the public interface. Most of our packages dont use it. When should they ?

ethanfrey commented 7 years ago

I think it is a good practice in general, when enough of the functionality is exposed to test decently. It has forced me a number of times to modify the API, as some interesting functionality was only possible through private methods (even if only needed for test setup, very good to be able to set up tests in other packages).

I don't use it sometimes when there is lots of logic in private methods and it is not practical to test without it. Or out of laziness. But I think it is usually good practice.

zramsay commented 7 years ago

cc @odeke-em

odeke-em commented 7 years ago

Thanks for the tag @zramsay!

Personally I prefer this style of X_test because as everyone has noted, it makes us test code through the public API. 2 other advantages:

With that being said, however, the comfort of the developer(Developer Experience) wins IMHO. We can slowly start adopting the style if everyone thinks it has more merit.

zramsay commented 6 years ago

see #46

jaekwon commented 6 years ago

Often you need to call internal functions because to expose certain functions is bad. We should take care to expose only those functions that need to be exposed, so it becomes necessary to keep certain tests internal.

Use external packages for integration testing.