ASP.NET Integration Testing

  Рет қаралды 15,141

Coding Tutorials

Coding Tutorials

Күн бұрын

Пікірлер: 43
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
Testing is one of the most important areas of software development. Any other aspects you want to know about? Source code available at: github.com/JasperKent/WebApi-Integration-Testing Remember to subscribe at kzbin.info/door/qWQzlUDdllnLmtgfSgYTCA And if you liked the video, click the 👍.
@schwamm1996kopf
@schwamm1996kopf Жыл бұрын
Hi Jesper thank you for your videos, they are really helpful! I have some suggestions for future videos: It would be nice to hear your perspectives on Design patterns and the architecture of applications. I love to hear perspectives from people with a lot of experience, because a new developer is bombarded with all these "SOLID" Principles and weird over-engineered architectures on the internet when in my opinion these things should just be "guidelines" that you probably should use, but only if your application has the need for them. Here is an example what the talking points in an "application architecture" video could be: - brief history of how architectures evolved over time - how to design a layer (e.g. Folderstructure) - why we use different layers - when should we add a new layer - differences and commonalities between different architectures (monolith, onion, hexagonal, microservices) - how to design a class - how to design a method (This is an important topic that is not talked enough about in my opinion) ... Examples of design patterns videos could be: - when and why exactly should we use them - different implementations of the pattern (more "complicated" implementation vs "simple" implementation and when to use which one) (I only ever see complicated implementation of patterns, which in my opinion could be written much simpler for a lot of applications) - related/similar patterns and their differences There is a lot to talk about but so little good information on the internet. These topics are probably really dry, but I hope you consider these topics for your new videos. Thanks!
@CRBarchager
@CRBarchager Жыл бұрын
Funny. Was just talking about this approach with a colleague 30 minuts ago and then you released a video about it. Thank you!
@burakt5532
@burakt5532 Жыл бұрын
Thank you so much, sir. I have to do a presentation at my workplace and your video has gave me the key of integration tests in a breeze. I'm grateful.
@diegomelgar2696
@diegomelgar2696 Жыл бұрын
Amazing!!! Another in time video I was looking for, thank you very much Jasper!!
@innocentversace1797
@innocentversace1797 Жыл бұрын
Thank you so much as a young developer. Your videos are giving me so much in depth knowledge. I will start a private project doing Intergration test for the current api I am developing.
@ikeuzoma9883
@ikeuzoma9883 Жыл бұрын
Amazing video! Thank you so much for explaining it so well
@sujitwarrier4857
@sujitwarrier4857 Жыл бұрын
Amazing video!! This channel needs to be seen more.
@mirekmiedziarek51
@mirekmiedziarek51 Жыл бұрын
Brilliant! Thanks for that valuable content.
@webnoel
@webnoel 11 ай бұрын
Hi Jesper, thank you for your explanation. A few things are clear to me now, however considering that this is integration testing, I would like to hear your opinion on mocking in integration tests. As I understand it, mocking a repository in an integration test goes against the essence of an integration test that is meant to test the end-to-end flow. In your example, the scope of the test only covers an http call made to the controller. It does not cover the repository and the database.
@CodingTutorialsAreGo
@CodingTutorialsAreGo 11 ай бұрын
There are three kinds of tests. Unit Tests test individual components. End-To-End tests test the entire application from UI to DB. Integration tests are somewhere in between, test how some - but not all - of the components interact. Here, we're testing how the controllers integrate with ASP.NET itself. If we also tested through to a real database, that would become E2E. We'd lose focus on what it is we're testing (the controller/ASP.NET interaction) and we'd have to do extra work to populate and clear some kind of test DB>
@MrLedsky
@MrLedsky Жыл бұрын
Thanks for video. It's so curious. But I've a one concern about Mocking for integration tests. Integration tests are needed specifically to test a part and including the database. And using Mock is not correct in my opinion.
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
That's a matter of definition. Integration tests are there to test more than units (i.e. individual classes) but less than end-to-end tests (the entire application). Unfortunately, it's a vague term. An integration test can test the routing and not the DB (as this does) or the DB and not the routing.
@diegomelgar2696
@diegomelgar2696 Жыл бұрын
hi Jesper, one question. If your API is configured with SnakeCase naming convention to translate the request payload to PascalCase request classes and response classes with PascalCase to snake_case to as the response. How to setup the BaseTest or the factory.CreateClient() to make the client requests made in the test fact are transform to snake case convetion? Let's say for example: var response = await _client.PostAsync("api/v1/auth/register", JsonContent.Create(new { FirstName = "john", LastName = "doe", // more attributes })); internally, what is required is that the request is transformed to { "first_name": "john", "last_name": "doe" }
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
There's a new feature in .NET 8 to support this: learn.microsoft.com/en-gb/dotnet/core/whats-new/dotnet-8#naming-policies
@diegomelgar2696
@diegomelgar2696 Жыл бұрын
@@CodingTutorialsAreGo thanks! This means that for each test, the practice would be to serialize the object before sending it to the api, right?
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
Just pass the options object into the overload of JsonContent.Create.
@diegomelgar2696
@diegomelgar2696 Жыл бұрын
@@CodingTutorialsAreGo Nice, thanks!
@vespuxi2516
@vespuxi2516 Жыл бұрын
You saved my day witha small detail !!!! cheers
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
Which detail was that?
@philippelombaers
@philippelombaers Жыл бұрын
Hi Jasper. Thanks. I'd like to know how to create integration tests for gRPC service.
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
I'll put it on the list.
@innocentversace1797
@innocentversace1797 Жыл бұрын
How can I further my knowledge on this topic. A book recommendation / documentation will be very welcome
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
This looks like a good resource: code-maze.com/aspnet-core-integration-testing/
@elias.clsn.92
@elias.clsn.92 Жыл бұрын
Such an amazing video! Thank you
@SumayaAli-q2h
@SumayaAli-q2h Жыл бұрын
Amazing!! many thanks.. very helpful tutorial :) I wounder if (in Memory) testing data belongs to unit test or integration test?
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
It's always a point for debate. I'd say unit.
@zazhigai_moto
@zazhigai_moto Жыл бұрын
Just in time. Thank you.
@HaymanotDemis-w3u
@HaymanotDemis-w3u Жыл бұрын
Really awesome. Thank you👍👍👍
@dvldev
@dvldev Жыл бұрын
Well it helped a lot. But I didn't understand why we want Moq?
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
Moq as opposed to writing our own mocks or as opposed to using a real database?
@dvldev
@dvldev Жыл бұрын
According to latest news many users of Moq have noticed that it is not safe. Because the Creator of the Moq has also created the Sponsor Link Nuget package and he add it to Moq. This maybe puts your data at risk and the best thing is to change it with NSubstitute Nuget. However, you can use a dummy database, a copy of your production database to do all tests. This as option sounds good, isn't it?
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
You could use a dummy database, but it would slow down the tests and be additional development work on the tests, when what you're trying to test is the API interaction, not the database interaction. An end-to-end test would use such a database.
@iamacsel87
@iamacsel87 Жыл бұрын
hi, great video! if i understand correctly for the integration test, you're not actually accessing the db? would it be better to make an integration test with a db (managing test data so there's no conflict or using containers for db) in which case both the db and api calls would be tested together in the same test without needing fake data for testing the api? also, i'm trying to understand the difference, is "mockRepository" actually a stub since it's not the subject being tested? thank you
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
Integration test is quite a vague term. A Unit Test tests a single class or very tight group of classes. An End-to-End test test the entire application. An Integration test is somewhere in between. So an integration test could test a live DB as long as it didn't, say, test the GUI. Even so, you'd need fake data. You don't want to test against real data, because real data changes. The fake data would have to be added before the test and removed after it. Personally, I find the precise distinctions between fakes, dummies, mocks, spies etc. add no benefit to the process, so I don't bother with them. But if you want to be precise (and it's just a personal preference), then you are correct.
@mohsin1017
@mohsin1017 Жыл бұрын
What if the api we are testing need authentication?
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
That's the subject of some upcoming videos.
@stevemcqueen2887
@stevemcqueen2887 Жыл бұрын
Thanks but "_client = _factory.CreateClient()" is giving the error 'System.InvalidOperationException: 'The server has not been started or no web application was configured.' Might be my API?
@CodingTutorialsAreGo
@CodingTutorialsAreGo Жыл бұрын
Very odd. CreateClient() doesn't make any attempt to access the server - it's only when a request is sent. Are you sure that's where the exception is being raised?
@stevemcqueen2887
@stevemcqueen2887 Жыл бұрын
You can add services.AddLogging(builder => builder.AddConsole().AddDebug()); to your builder.ConfigureTestServices() to see the output logs. In my case, I have Hangfire installed in my API and that was failing to build.
@ukpachalla
@ukpachalla Жыл бұрын
Loved it.
@zenluiz
@zenluiz Жыл бұрын
Great video
The Best Way To Use Docker For Integration Testing In .NET
19:34
Milan Jovanović
Рет қаралды 38 М.
ASP.NET Core Integration Testing Tutorial
24:35
Julio Casal
Рет қаралды 28 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
Writing tests in .NET using xUnit -  xUnit Tutorial
25:50
Nick Chapsas
Рет қаралды 130 М.
WebAPI Versioning
17:58
Coding Tutorials
Рет қаралды 2,1 М.
Lists Practical
17:37
Zakaria abusilmiyeh
Рет қаралды 94
.NET Core Integration Testing Basics
14:41
Vasilii Oleinic
Рет қаралды 5 М.
Integration testing | ASP.NET Core 5 REST API Tutorial 15
22:13
Nick Chapsas
Рет қаралды 111 М.
Building a .NET 6 API Using TDD
1:38:59
Wes Doyle
Рет қаралды 148 М.
C# Integration Testing Tutorial
40:25
Raw Coding
Рет қаралды 36 М.
C# Unit Testing Best Practices for Great Code Coverage
17:52
Milan Jovanović
Рет қаралды 29 М.
The Best Way To Write Parameterized Tests In .NET Using xUnit
12:29
Milan Jovanović
Рет қаралды 15 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН