3 ms·
For writing production software, I have the same kind of concerns. Plus, what if you want do something more than simple unit tests (property based testing, conc
by lliamander 10y ago
For writing production software, I have the same kind of concerns. Plus, what if you want do something more than simple unit tests (property based testing, concolic testing, etc) or if someone comes up with a better unit testing framework? You'll still have to setup those tests in a separate file, and then the in-line tests are just some unused feature of the language.
However, for educational purposes, I think it's actually a compelling idea. My perspective is that while unit tests are a great idea, each unit test only provides marginal value. Thus, unit tests need to be as easy and natural to write as possible or developers won't do it.
Habits, like writing code that doesn't need much mocking, definitely makes TDD easier, but that often comes after habituating oneself to TDD. For students, I think getting them as early as possible to write unit tests would be a big win. Putting the tests right there in the code with no need to set up test infrastructure or learn a separate test framework will be helpful.