You arrange things where you
- want to make sure your algorithm works.
- want to protect against accidental changes in the future
So, in your example, it would not make sense to test the generated classes. Instead, test the generator.
It is good practice to verify the main use cases (which was designed for the first function). Then you check for basic errors. Then you write tests for corner cases (i.e. lower and upper bounds). Unusual cases of errors are usually so complex that it makes no sense to test them.
If you need to test a large set of parameter sets, use data-driven testing.
How many things you test is a matter of effort or return, so it really depends on the individual project. Usually you try to follow the 80/20 rule, but there may be applications where you need more test coverage, because a failure will have very serious consequences.
You can significantly reduce the time it takes to write tests if you use the test approach (TDD). This is because code that is not written with the ability to test is much more complicated, sometimes almost impossible to verify. But since nothing in life is free, code developed with TDD tends to be more complex.
TToni
source share