| ▲ | zelphirkalt 15 hours ago | ||||||||||||||||
The easiest thing to test will always be pure functions. Many people don't realize this, and how clean it can make your tests look. Provide input, get return value, assert/check it. Sure, at the end of the day you have some IO somewhere. But that will usually be a smaller part of the code base. Codebases that make testing more difficult than that, are making it unnecessarily complicated. Sometimes you depend on some library that forces you or heavily nudges you into another style, that can happen. But what one wants to avoid is a codebase, where one has to know to mock 5 other things because of their side effects. | |||||||||||||||||
| ▲ | MangoToupe 13 hours ago | parent | next [-] | ||||||||||||||||
> But that will usually be a smaller part of the code base. Testing how IO composes makes up most of what you want to test because it's such a difficult problem. Reasoning about this in terms of size of the codebase doesn't make sense. | |||||||||||||||||
| |||||||||||||||||
| ▲ | tormeh 13 hours ago | parent | prev | next [-] | ||||||||||||||||
Exactly. Divide the code in impure and pure functions. The pure functions can be easily unit tested. The impure ones can often be integration tested. The rest you'll just have to live with (or cover with whole-process integration tests). For tests spanning larger chunks of your code base it might be worth it to mock impure code. Never mock pure code - that's madness. | |||||||||||||||||
| ▲ | 9rx 12 hours ago | parent | prev [-] | ||||||||||||||||
Trouble is that in an application the pure functions are just implementation details that don't need to be tested. They get tested by virtue of a correct implementation being necessary to correctly run the application. A library can be a little different story, as there the public interface is quite likely to be pure, but I expect most codebases found in the wild are applications. The discussion happening here seems to be directed at applications. Granted, it appears Rust gets a lot of use as a cross-language library provider, where the application glue is written in other languages. Perhaps that's why? | |||||||||||||||||