Skip to main content
added 2 characters in body
Source Link
Kilian Foth
  • 110.3k
  • 45
  • 300
  • 321

You need unit tests in proportion to the risk that the code in that class introduces an error.

Complex code is more risky than simple code. Long methods are more risky than short ones. Code that implements decisions is more risky than code that simply funnels values to somewhere else, etc. Therefore, as long as your controller layer does nothing but copy values from one place to another, it has the lowest priority for writing tests. But having tests is still better than not having them - even the simplest code can introduce errors, particularly since you believe it's simple and check it last if something goes wrong.

Note that if the entire layerentire layer is so straightforward and repetitive that it really only repeats actions at another layer, the right thing to do is to have it auto-generated, write a test for the auto-generator, and then never worry about it again.

You need unit tests in proportion to the risk that the code in that class introduces an error.

Complex code is more risky than simple code. Long methods are more risky than short ones. Code that implements decisions is more risky than code that simply funnels values to somewhere else, etc. Therefore, as long as your controller layer does nothing but copy values from one place to another, it has the lowest priority for writing tests. But having tests is still better than not having them - even the simplest code can introduce errors, particularly since you believe it's simple and check it last if something goes wrong.

Note that if the entire layer is so straightforward and repetitive that it really only repeats actions at another layer, the right thing to do is to have it auto-generated, write a test for the auto-generator, and then never worry about it again.

You need unit tests in proportion to the risk that the code in that class introduces an error.

Complex code is more risky than simple code. Long methods are more risky than short ones. Code that implements decisions is more risky than code that simply funnels values to somewhere else, etc. Therefore, as long as your controller layer does nothing but copy values from one place to another, it has the lowest priority for writing tests. But having tests is still better than not having them - even the simplest code can introduce errors, particularly since you believe it's simple and check it last if something goes wrong.

Note that if the entire layer is so straightforward and repetitive that it really only repeats actions at another layer, the right thing to do is to have it auto-generated, write a test for the auto-generator, and then never worry about it again.

Source Link
Kilian Foth
  • 110.3k
  • 45
  • 300
  • 321

You need unit tests in proportion to the risk that the code in that class introduces an error.

Complex code is more risky than simple code. Long methods are more risky than short ones. Code that implements decisions is more risky than code that simply funnels values to somewhere else, etc. Therefore, as long as your controller layer does nothing but copy values from one place to another, it has the lowest priority for writing tests. But having tests is still better than not having them - even the simplest code can introduce errors, particularly since you believe it's simple and check it last if something goes wrong.

Note that if the entire layer is so straightforward and repetitive that it really only repeats actions at another layer, the right thing to do is to have it auto-generated, write a test for the auto-generator, and then never worry about it again.