Master ASP.NET Core Integration Testing: Learn How TestContainers and WebApplicationFactory Can Help

Поделиться
HTML-код
  • Опубликовано: 17 ноя 2024

Комментарии • 59

  • @palandorent
    @palandorent 11 месяцев назад +1

    you saved my ass i have been trying to get integration tests running for 6 hours and after your video everything worked THANK YOU SO MUCH

    • @Foad_Alavi
      @Foad_Alavi  11 месяцев назад

      I am glad it was useful

  • @ransandu
    @ransandu Год назад +4

    Thank you very much. Please list down all the challenges/pitfalls we gonna face with this approach.

    • @Foad_Alavi
      @Foad_Alavi  Год назад +1

      Hi Ranga, thank you for your comments.
      I explain three different approaches which of them do you mean specifically?

    • @ransandu
      @ransandu Год назад +1

      @@Foad_Alavi, Thanks for your response. Plase see below:
      How to configure running integration tests in CI pipeline.
      How to handle side effects:
      e.g.
      Sending notifications:
      Call other services during the process:

      Should we switch off side effects when running integration tests?
      Should we mock all the dependent services?

      Should we run integration tests in our usual CI pipeline? Since it takes time to spin containers etc.
      Please provide your recommendations.
      Thanks in advance for your feedback.

    • @Foad_Alavi
      @Foad_Alavi  Год назад +3

      @@ransandu Hi Ranga, I will create a video and explain all your questions there

    • @Foad_Alavi
      @Foad_Alavi  8 месяцев назад +1

      I uploaded the first video about how to use it in Azure Pipeline.
      ruclips.net/video/7bBDOgVK8r4/видео.html
      Most of your questions will be answered in the second video, so do not miss them ;-)

    • @ransandu
      @ransandu 8 месяцев назад

      @@Foad_Alavi thanks. I'll surely watch it.

  • @qasimmughal1396
    @qasimmughal1396 5 месяцев назад

    Thanks for your explanation. You are a wonderful teacher

  • @tomaszbaginski7467
    @tomaszbaginski7467 9 месяцев назад

    Awesome, thanks! That would be good to cover authentication approaches for integration tests.

  • @2784raj
    @2784raj 7 месяцев назад

    Awesome Explation, great tutorial for .net Developer

  • @hesamkalhor3263
    @hesamkalhor3263 Год назад

    Another great demonstration and explanation. Thanks for sharing.

  • @فربدعلیخانی-ز8ت
    @فربدعلیخانی-ز8ت 4 месяца назад

    موفق باشی فواد 🤟

  • @mhadi.h
    @mhadi.h 10 месяцев назад

    Thank you Foad. Amazing content.

  • @Pablo-dq9mw
    @Pablo-dq9mw 2 месяца назад

    Thank you dude you helped me so much

  • @nandotox13
    @nandotox13 10 месяцев назад

    Hi , thanks for the video , exactly what I was looking for using testContainers , one question how can you handle the API Authentication if the API is [Authorize] with Azure AD ? thanks

    • @Foad_Alavi
      @Foad_Alavi  10 месяцев назад

      You need to mock or remove the Auth services in WebApplicationFactory.

  • @rohanwankhede2223
    @rohanwankhede2223 Год назад +1

    Thanks. Good info and nicely explained 😀

  • @ravikirangutti1577
    @ravikirangutti1577 5 месяцев назад

    Very good explanation, Can you make it video for integration tests for cosmos db

  • @PelFox
    @PelFox 8 месяцев назад

    What's often not covered by these tutorials is auth. How do you integration test your API with oauth token protection? Because more often than not your API is behind some auth and you also want to ensure that it's protected as expected.
    Do you:
    1) Generate a real token and use it for all tests?
    2) Mock it?
    3) Other?

    • @sakaido4400
      @sakaido4400 8 месяцев назад

      Well i think writing testauthhandler class that inherited from authenticationhandler and doing basic configuration would be fine but idk about if docker is changing the process.If auth was covered this video would be 10/10 as u say.

    • @Foad_Alavi
      @Foad_Alavi  8 месяцев назад

      Good question.
      I haven't added this scenario to avoid making the project too complicated.
      For integration tests, I usually create a token, use this token in a fixture class, and use a method to add the auth token to the request header.

  • @andresbeltran5779
    @andresbeltran5779 9 месяцев назад

    Amazing tutorial, thx for sharing

    • @Foad_Alavi
      @Foad_Alavi  9 месяцев назад

      You’re welcome 😊

  • @BarbarosYurttagul
    @BarbarosYurttagul 9 месяцев назад

    Thanks for this nice video. I checked your other videos but I couldn't see any video how we can configure running integration tests in CI pipeline with TestContainers.

    • @Foad_Alavi
      @Foad_Alavi  9 месяцев назад

      Integration with an Azure CI pipeline would be a bit tricky, especially if you are using Linux based agents.
      I gave a presentation about how to do that in a development conference. I can create a short video about that if more people are interested about that.
      The technique that we can use for this is to use a docker wormhole.

    • @BarbarosYurttagul
      @BarbarosYurttagul 9 месяцев назад

      @@Foad_Alavi maybe in github actions?

    • @Foad_Alavi
      @Foad_Alavi  8 месяцев назад +1

      I uploaded the first video about how to use it in Azure Pipeline.
      ruclips.net/video/7bBDOgVK8r4/видео.html
      In the following 2 videos, I will explain how it works and why we need to wrap our solution in a Docker image, so do not miss them ;-)

    • @BarbarosYurttagul
      @BarbarosYurttagul 8 месяцев назад

      @@Foad_Alavi thank you very very much

  • @thiagoclassen1979
    @thiagoclassen1979 6 месяцев назад

    Is it possible to attach the debugger on the WebApiFactory so you can debug the api while run the tests?

    • @Foad_Alavi
      @Foad_Alavi  6 месяцев назад

      Yes you can easily do that
      Just put a break point in a place you need to debug

  • @alireza136211
    @alireza136211 Год назад

    very well explained, Thank you

  • @mateabulashvili2821
    @mateabulashvili2821 10 месяцев назад

    very useful video, thanks for that

    • @Foad_Alavi
      @Foad_Alavi  10 месяцев назад

      Glad it was helpful!

  • @andresbeltran5779
    @andresbeltran5779 9 месяцев назад

    Im having a problem, the test runs perfectly but when the process finish, throws an error [Test Class Cleanup Failure (DatabaseProject.Test.Controllers.WithTestContainer)]: Docker.DotNet.DockerApiException : Docker API responded with status code=InternalServerError, response={"message":"cannot remove container \"/boring_tu\": could not kill: container a9991e425e3a PID 8972 is zombie and can not be killed. Use the --init option when creating containers to run an init inside the container that forwards signals and reaps processes"}. Any ideas?

    • @Foad_Alavi
      @Foad_Alavi  9 месяцев назад

      I will try to check it today or tomorrow and see what can be the issue.

    • @andresbeltran5779
      @andresbeltran5779 Месяц назад

      @@Foad_Alavi I come back to this video 8 months later and it finally works. I don't know what I did wrong last time

  • @harimuhammad4525
    @harimuhammad4525 5 месяцев назад

    awesome!

  • @jensingels5958
    @jensingels5958 Год назад

    Is IAsyncLifetime not been deprecated since 2021? Which benefit would this have over the more generic IDisposable?

    • @Foad_Alavi
      @Foad_Alavi  11 месяцев назад

      I'm sorry for not getting back to you sooner. I was busy with house renovation and got ill after that.
      I am not sure if it is correct. This interface in the GitHub repo is not marked as obsolete.

  • @BartoszSeweryn-h2p
    @BartoszSeweryn-h2p 10 месяцев назад

    What if i have table with some constraints, for example Order has a column with foreign key ProductId, how to mock it

    • @Foad_Alavi
      @Foad_Alavi  10 месяцев назад

      In integration testing, we do not really test the database; we test the boundaries of our application and check whether we can use the database.
      If you elaborate a bit more, I might be able to help you.

  • @kandycan
    @kandycan 8 месяцев назад

    great tutorial.

    • @Foad_Alavi
      @Foad_Alavi  8 месяцев назад

      Glad you liked it!

  • @rajeevgandhi3473
    @rajeevgandhi3473 Год назад

    Thanks for the video.

  • @davood7497
    @davood7497 9 месяцев назад

    Good job !!!

  • @mohsenmahabadi84
    @mohsenmahabadi84 Год назад

    Awesome🤞

  • @stiermate3122
    @stiermate3122 11 месяцев назад

    more videos🔥

  • @nagwaahmed4600
    @nagwaahmed4600 Год назад

    Excuse me but can i change the connection string?

    • @Foad_Alavi
      @Foad_Alavi  Год назад +1

      By making some changes to MsSqlContainer implementation, you can.
      I made the changes in this feature branch and used a custom database name, username, and password.
      github.com/foadalavi/Test-Foundation-playlist/tree/Feature/MsSqlContainer/Fix/IntegrationTest_Database
      If you want to change the server IP address, you need to create a network at the docker level, which is not straightforward.

    • @nagwaahmed4600
      @nagwaahmed4600 Год назад

      @@Foad_Alavi thanks you saved me

    • @nagwaahmed4600
      @nagwaahmed4600 Год назад

      can I restore a backup for exist database to test it?

    • @Foad_Alavi
      @Foad_Alavi  Год назад +1

      I just added functionality to this feature branch o accept a file path to restore. You need to call 4 fluent methods:
      .WithDatabase("School")
      .WithPassword("$tr0ngP@$$w0rd")
      .WithUsername("MyUser")
      .WithRestore(@"C:\Users\foada\School.bak")
      The database name must be the name of the database you are going to restore.
      I hope it helps you.

    • @nagwaahmed4600
      @nagwaahmed4600 Год назад +1

      @@Foad_Alavi i will try it thanks

  • @jensingels5958
    @jensingels5958 Год назад

    45:40, wouldn't that cause a nasty memory leak in some situations? Doesn't make sense Docker uses the master for it.

    • @Foad_Alavi
      @Foad_Alavi  11 месяцев назад

      Can you please elaborate more? What makes a memory leak?