| ▲ | 9rx 2 days ago | |||||||||||||||||||||||||
> I wonder if it would technically be possible to only compile with duck typing in test Not exactly the same thing, but you can use build tags to compile with a different implementation for a concrete type while under test. Sounds like a serious case of overthinking it, though. The places where you will justifiably swap implementations during testing are also places where you will justifiably want to be able to swap implementations in general. That's what interfaces are there for. If you cannot find any reason why you'd benefit from a second implementation outside of the testing scenario, you won't need it while under test either. In that case, learn how to test properly and use the single implementation you already have under all scenarios. | ||||||||||||||||||||||||||
| ▲ | the_gipsy 2 days ago | parent [-] | |||||||||||||||||||||||||
> The places where you will justifiably swap implementations during testing are also places where you will justifiably want to be able to swap implementations in general. I don't get this. Just because I want to mock something doesn't mean I really need different implementations. That was my point: if I could just duck-type-swap it in a test, it would be so much easier than 1. create an interface that just repeats all methods, and then 2. need to use some mock generation tool. If I don't mock it, then my tests become integration test behemoths. Which have their use too, but it's bad if you can't write simple unit tests anymore. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||