There are actually people claiming you shouldn't do unit test on private method ? what bullshit is this ???


@Ambraven Are they the same people who claim that unit tests are only useful for refactoring?


I'm not sure. They say "if you have to test a private method you should refactor" but I don't think it counts as "only useful for refactoring".

Also it's bullshit.


@Ambraven So basically black box testing where only the spec is checked not the implementation code? That's a way to cut effort


I'm beginning to think that some rationnailsation for old c++ users that can't test privates in a clean way so they decided it was bad practice actually.

@Ambraven @jkb For a properly designed type, if a method preserves the invariant it should be public, therefore private methods do not preserve it. Unit tests should verify and document invariants, not specific ways in which some intermediate step in the implementation happened to break them. This might not seem generally applicable, only because crippled (invariant preserving private methods) and leaky (invariant breaking public methods) interfaces are common place and standard practice.

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!