3 ms·
> At least when the controllers are all classes I can unit test them. So I've literally just jumped into this world, having never touched asp.net or similar be
by magicalhippo 5y ago
> At least when the controllers are all classes I can unit test them.
So I've literally just jumped into this world, having never touched asp.net or similar before.
I looked into how to test the controller side of things, and came across this[1] post arguing that unit testing controllers weren't as useful as integration testing them.
Integration testing would definitely be useful, and something I will do, but I assume also a lot more time-consuming so perhaps not something we could do on a per-commit basis.
Would highly appreciate views on this topic.
[1]: https://andrewlock.net/should-you-unit-test-controllers-in-aspnetcore/ https://andrewlock.net/should-you-unit-test-controllers-in-a...
- achtung82 5y agoIntegration testing as im used to it takes less time to write than unittests since you need to spend less time mocking things (mainly just mock external requests). Of course the initial setup requires more time but there are many readymade examples you can copy from. For example the official documentation. https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-5.0 https://docs.microsoft.com/en-us/aspnet/core/test/integratio...
- stonemetal12 5y agoUnit tests are valuable if you are doing some sort of "computation". If all code in question is doing is plugging x into y, then unit tests are useless and integration tests are where the payoff is. If you have code that does both plug and compute you should refactor them so that computing and plugging don't happen in the same place. Doing so will reduce instances of hard to test code. In general controllers are plugging code not computing code, so integration tests tend to be the more appropriate choice.