The Complete Guide to Functional Testing in ASP.NET Core (End-to-End Testing)

  Рет қаралды 27,835

Milan Jovanović

Milan Jovanović

Күн бұрын

Пікірлер: 49
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@idreamshub
@idreamshub 9 ай бұрын
I was actually waiting for this video to drop. Thanks Milan.
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Awesome, I hope it was helpful :)
@Adronius
@Adronius 8 ай бұрын
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).
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
Fair enough
@sevansoft
@sevansoft 2 ай бұрын
I would start with failure paths and end with happy paths. As long as you cover every scenario it doesn't really matter.
@Adronius
@Adronius 2 ай бұрын
@@sevansoft it matters when you test drive your code
@xavier.xiques
@xavier.xiques 8 ай бұрын
I love this kind of videos. Thanks Milan!!
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
You're very welcome!
@antonmartyniuk
@antonmartyniuk 8 ай бұрын
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
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
I consider it an integration test as long as it's using real external services
@padnom4991
@padnom4991 8 ай бұрын
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
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
I just talked about that in a recent video I was recording, for running integration tests in CI
@syedjunaid7846
@syedjunaid7846 9 ай бұрын
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
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
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.
@syedjunaid7846
@syedjunaid7846 8 ай бұрын
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?
@drhdev
@drhdev 9 ай бұрын
I use the exact same setup but call it an integration test. You can make this easier without TestContainers and just use a DbContext options factory.
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
It goes by many names, it's all integration testing as long as you use a real service under the hood
@syedjunaid7846
@syedjunaid7846 8 ай бұрын
@drhdev are you running your integration tests with live external services? The dB context options just let's you configure it for existing data bases
@devmarkmonster
@devmarkmonster 9 ай бұрын
This is pretty nice! How would you take the approach of functionally testing a Blazor application?
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
I guess something similar to Selenium? I don't do Blazor, but I expect something like that to be available
@harkiratsingh4947
@harkiratsingh4947 8 ай бұрын
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 ?
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
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.
@dudley810
@dudley810 2 ай бұрын
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?
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
No auth in this example. But we definitely want it in a real world scenario. I'll cover an example with Keycloak in the near future.
@dudley810
@dudley810 2 ай бұрын
@@MilanJovanovicTech thanks
@sevansoft
@sevansoft 2 ай бұрын
Instead of using your CustomProblemDetails, could you not use Validation ProblemDetails? 🤔
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
Yes, i could've used that
@sevansoft
@sevansoft 2 ай бұрын
OK cool, I wondered for a moment whether its avoidance was from deliberate reason that I was unaware of. Thanks 👍
@banster85
@banster85 9 ай бұрын
Great video! Thanks!!
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Glad you liked it!
@selmamehonjic6403
@selmamehonjic6403 7 ай бұрын
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 ?
@MilanJovanovicTech
@MilanJovanovicTech 7 ай бұрын
Why not create the appropriate token with claims before executing the test?
@bookuha
@bookuha 5 ай бұрын
@@MilanJovanovicTechAnd how would you do this in an integration test that only tests a MediatR handler?
@jonathansillak6511
@jonathansillak6511 6 ай бұрын
How to perform docker login with the TestContainers PostgreSql package?
@MilanJovanovicTech
@MilanJovanovicTech 6 ай бұрын
Don't need to, you can connect to it from the test
@caiocesardotcs
@caiocesardotcs 9 ай бұрын
What theme are you using in VS?
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Dark theme + ReSharper
@mattmarkus4868
@mattmarkus4868 6 ай бұрын
Is this code on your github account? I'd like to look at your request and response/result base classes. Thanks.
@MilanJovanovicTech
@MilanJovanovicTech 6 ай бұрын
The Result type? gist.github.com/m-jovanovic/aa25b1ae424c985ff8ae696a79b6fe6e
@sajadmalik9097
@sajadmalik9097 4 ай бұрын
Can I access this codebase somewhere?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Check out this: github.com/m-jovanovic/testcontainers-sample/
@umutkayatuz9963
@umutkayatuz9963 8 ай бұрын
Authentication and Authorization part is missing.
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
Grab a Cookie/JWT and add it to the request, shouldn't be too hard
@sunzhang-d9v
@sunzhang-d9v 9 ай бұрын
CustomResult and result.Match ? I don't know
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
It's a ProblemDetails, just a helper to let me turn the Result object into ProblemDetails
@sunzhang-d9v
@sunzhang-d9v 9 ай бұрын
@@MilanJovanovicTech I can't follow in your footsteps like this, there are many updates in many places, we don't know
The Best Way To Use Docker For Integration Testing In .NET
19:34
Milan Jovanović
Рет қаралды 36 М.
How to Add Health Checks in ASP.NET Core
11:51
Milan Jovanović
Рет қаралды 19 М.
MY HEIGHT vs MrBEAST CREW 🙈📏
00:22
Celine Dept
Рет қаралды 103 МЛН
ЗНАЛИ? ТОЛЬКО ОАЭ 🤫
00:13
Сам себе сушист
Рет қаралды 3,9 МЛН
Это было очень близко...
00:10
Аришнев
Рет қаралды 7 МЛН
У вас там какие таланты ?😂
00:19
Карина Хафизова
Рет қаралды 17 МЛН
2 Best Practices for Returning API Errors in ASP.NET Core
12:39
Milan Jovanović
Рет қаралды 27 М.
ASP.NET Core Integration Testing Tutorial
24:35
Julio Casal
Рет қаралды 25 М.
[Beginner Friendly] Blazor CRUD with Import & Export Excel  Part 3
19:59
Find Intersection Between Arrays (Data Structures & Algorithms)
0:52
Completely Get Rid of Exceptions Using This Technique
19:24
Milan Jovanović
Рет қаралды 26 М.
The New Global Error Handling in ASP.NET Core 8
13:41
Milan Jovanović
Рет қаралды 44 М.
Unit Testing Business Logic The Right Way | Full Tutorial
23:52
Milan Jovanović
Рет қаралды 13 М.
How To Build an API Gateway for Microservices with YARP
12:42
Milan Jovanović
Рет қаралды 22 М.
MY HEIGHT vs MrBEAST CREW 🙈📏
00:22
Celine Dept
Рет қаралды 103 МЛН