3 ms·
Well, not lending itself to testing really is a big problem. But one does not need to sacrifice much in terms of understandability to make code testable. For in
by cjfd 5y ago
Well, not lending itself to testing really is a big problem. But one does not need to sacrifice much in terms of understandability to make code testable. For instance, one does not always need an interface. You could also just inherit from the thing that you want to mock. Another problem that might be going on here is that you might be trying to test on a level that is too low. I think it is in many cases not a good idea to test individual classes and methods. Often it is better to test some small number of classes working together. The problem with testing one single class or method is that you are likely testing implementation details that are very much subject to change and also that at some point one is testing trivial things like 'is the standard library of my language still capable of adding items to a container'. When testing at a bit of a higher level one can write tests that are about properties of the software that are actually valued by the customer. These are much more likely to be stable. If one tests at a level that is a bit higher, one also needs to mock fewer things so the interface thing is also less likely to be much of a problem.
- _benj 5y agoThat makes sense a lot of sense. I guess the thing is that golang and their are stdlib testing lends itself to unit testing and not so much to integration testing. Our system also talks to a bunch of hardware via multiple protocols, for which we’d need to write simulators (so I’ve written but mostly for development and not for testing) And apart from that, it being an async user facing gui app… well, automated testing is kind of a challenge :) But you are right, I can think of a few things that can be tested, bigger than methods but smaller than end-to-end testing