Hacker News new | ask | show | jobs
by tigershark 3669 days ago
Because it's a waste of time and it clutters unnecessarily your test codebase. I prefer to invest my time to create better tests/code rather than creating manually test objects when I can simply do something like this:

    var authenticationService = Substitute.For<IAuthenticationService>();
    authenticationService.Authenticate("goofy").Returns(true);
    authenticationService.Authenticate("Donald duck").Returns(false);
In another test I can easily create a mock that returns true regardless of the users to go on with testing other parts of the code. In your case you need to create two concrete objects that will have a different behaviour. And what if you need a test that checks that users with some roles need to be authorized? And other members of your team need to search for an existing manual mock otherwise they may end adding some utterly useless duplicated manual mock, and in big teams you can see that it can be easily a huge mess. If you are the only person to write code it's up to you to waste your time, but in a shared codebase you need to be mindful of other people.