News for hackers. Stuff that matters.
Re:Minimal APIs at a glance in .NET 6 by magicalhippo on Monday September 13, 2021 @09:22AM (#28511147)
> 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-a...

Re:Minimal APIs at a glance in .NET 6 by stonemetal12 on Monday September 13, 2021 @11:06AM (#28512418)
Unit 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.

Re:Minimal APIs at a glance in .NET 6 by achtung82 on Monday September 13, 2021 @11:00AM (#28512341)
Integration 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/integratio...