4 ms·
This is nice in theory, but you need to design everything to work dependency injection style (or really have a setter for everything) to achieve this. Using a r
by viraptor 8y ago
This is nice in theory, but you need to design everything to work dependency injection style (or really have a setter for everything) to achieve this. Using a random number? Store the generator. Opening a file? Use a "FooOpener". ...
Sometimes it's easier just to stub what you want.
- dhimes 8y agoYeah- Sometimes I've gotten lazy and returned an object that has all the private stuff attached. Once I've verified that it works, I quit returning that object, keeping the methods private for normal use. It gives me a clear logical delineation yet allows me to test while developing.
- arkh 8y agoIf you can't put the thing you're testing (method, class, application) in the state you want to test using only public methods you are not testing something useful. If you're doing to get 100% coverage be happy: that's dead code you can remove.
- viraptor 8y agoCounterexample: Testing something that uses your language's Array.shuffle equivalent which doesn't expose the randomness provider. You can't put it in the right state without just stubbing the call and making it return the order you want.