Great video! Thank you! Just a small tip: When creating a test list, start with happy path and end with edge/exceptional cases (not the other way around).
Some call it behaviour tests, other call integration tests. I prefer the 2nd and it's the kind of tests I am writing for my webapps. I like it calling integration tests, because it tests the app from the webapi down to the database, the whole application logic in other words. For simple web apis or most of microservices it's enough, but for complex db logic I additionally write integration tests for my repositories
Great vidéos . I use test collection in order to share test container and avoid to create to many database . And for each test I reset the DB with snapshot or respawn
If there was authentication/authorization setup, would you put the mocks/overrides for the auth schemes in the factory class? And how would you pass different claims to it if you wanted to dynamically mock different claims. I'm not sure on the structure.i was thinking pass data to the base class, which calls a method on the factory class to override some services. I don't know if that's a clean way
Ideally, I wouldn't mock Authentication at all. I covered that in my course, for example. I'm using Keycloak for auth, and in functional tests I'm first getting the JWT before running the tests.
Oh okay that makes sense. Thanks. I read your article on resource based auth in CA. Interesting because I'd have usually put the auth logic in the api layer using policies of some sort So if you wanted to mock the authenticated user you would opt for mocking that during subcutaneous testing , basically sending a MediatR req?
Where does authentication / authorization get done? I am thinking the microservice does not have any security in it and then you would handle all that in a proxy like konghq or Apigee? This would allow you to do the testing without messy with security. Is this a correct statement?
I am struggling to understand the difference between unit tests and functional tests , or are they the same ? I use to write unit tests but without docker, test-containers, web application factory. What is the benefit of this approach ?
They are not the same. Unit tests just test a simple unit - class/service/method. Functional tests actually execute the ASP.NET Core application and run the tests. Huge difference.
I handle authorization part with AuthenticationHandler by overriding HandleAuthenticateAsync to use claims, found that there is a pretty common way to handle authentication part, but couldn't find the way to provide different claims for each test. What will bi the proper way to do such a thing ?