Hacker News new | ask | show | jobs
by lectrick 4639 days ago
I think this was only a poor example because the method under test was a "director" style method (not sure what the name of it would actually be) that simply forwards a bunch of messages/commands to other objects and doesn't do much actual logic/computation.

Tests for these "director" style methods must by nature assert that all the right messages were forwarded to the right objects under the right circumstances, so yes, you do end up with tests that look a lot like what they're testing.

Agreed that ideally you are only testing ins and outs though, but I think this case was exceptional.

2 comments

It is better to not have a test at all than to have a test that looks a lot like what it is testing. I never uderstood that crazy push for 100% unit test coverage that some are advocating. Unit tests are just one tool among many. Use with care and where appropriate.
I think this is actually an argument that the tests are telling us that having a controller class this shape isn't the design we should aim for.