Learn the 'Insider Trick' I Use to .NET Integration Testing with Docker Compose!

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 พ.ย. 2024

ความคิดเห็น • 20

  • @lldadb664
    @lldadb664 หลายเดือนก่อน

    Today I learned: test containers. Thanks for the lead to the concept and the modifications!

    • @gui.ferreira
      @gui.ferreira  22 วันที่ผ่านมา +1

      Glad it was helpful!

  • @MilanJovanovicTech
    @MilanJovanovicTech ปีที่แล้ว +6

    I've wanted to start working with Test Containers for a long time. This is really helpful to solve some questions I had about using it. Much appreciated.

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      Glad to hear. Keep in mind that what I show here is an alternative to the common practice when using TestContainers.

    • @MilanJovanovicTech
      @MilanJovanovicTech ปีที่แล้ว

      @@gui.ferreira Did you ever try running test containters in a build pipeline like GitHub actions?

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว +1

      @@MilanJovanovicTech Not on GitHub Actions, but on TeamCity.

  • @hetman1x
    @hetman1x ปีที่แล้ว +2

    Top content, I'm going to use it in my projects. Thank you!

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      Thanks, Vadym! 🙏
      Let me know how did it go!

  • @FatMooseHenry
    @FatMooseHenry ปีที่แล้ว +2

    How do you handle port conflicts? If you are running the containers from docker compose when developing so that they are running when you run the test. Wont you get an error saying that the port is already allocated?

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      That's not my type of workflow. I test-drive first and then I might run docker-compose manually for manual testing. So, I never got to a port conflict.
      However, in your use case, I would create an override like is explained here: mindbyte.nl/2018/04/04/overwrite-ports-in-docker-compose.html

  • @julienlefevre1661
    @julienlefevre1661 ปีที่แล้ว +1

    Hello :) thanks for this video that provides practical example. I'm also interested in the implementation of integration tests with SQL Server Database during CI. Once my Azure pipeline is running I'm facing issues. Seems my connection string doesn't find the SQL Server :/ Any idea? Kind regards

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      Hi! Are you running the SqlServer in a container? Are you using the docker-compose as I show in the video? Can you see in the pipeline logs that the SQL Server started successfully?

  • @DJEAUK
    @DJEAUK ปีที่แล้ว +1

    Hi Gui. I downloaded the code for this and it works really well. Thanks for sharing. 🙂 I wanted to ask if in your experience you shared the same docker container across all the integration tests or you create a container for each one of the test classes.

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว +1

      Hi! Thanks 🙏
      I use the same Test Fixture on all the test classes that will need those containers, so they run faster.

    • @DJEAUK
      @DJEAUK ปีที่แล้ว +1

      @@gui.ferreira - I created for my use case a global strategy for NUnit. I have a global setup and tear down for the assembly. The two methods take care to create the container before running the tests and destroy it after running the tests. Do you have any raccommendation on how to speed them both locally and on Azure?

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว +1

      ​@@DJEAUK I'm not experienced in NUnit but looks like you are doing exactly what I'm saying. The only difference may be that you are relating that to the assembly, and with xUnit, you may have multiple Fixtures on your tests.
      Regarding speed optimizations, the only recommendation is to make sure you pin container versions and don't bring stuff into the docker-compose file that is not required. Besides that, I know that some platforms have a caching system for container images. I think that I've seen that in GitHub Actions.

    • @DJEAUK
      @DJEAUK ปีที่แล้ว +1

      @@gui.ferreira - thanks for you feedback. Using the overriding capability of docker compose, I keep multiple docker compose files and orchestrate the stack composition with a bash script. Therefore, I have docker compose file per resource. Using the approach you shared in the video, now I can load a single docker compose file for the integration tests, in the specific the database server. For CI/CD, I have a requirement of using Azure DevOps Pipelines. I need to see if they offer a caching system in the hosted agents.
      Thanks for sharing your idea. It helped me a lot.
      Keep up with the good work!

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว +1

      @@DJEAUK Thanks for the support 🙏

  • @vibes992000
    @vibes992000 5 หลายเดือนก่อน +1

    how do you handle kafka (or rabbitmq) server startup delay in `docker-compose.yaml` or at fixature level? I often end up running and crashing web server first even after using `depend_on` attribute in `docker-compose.yaml`

    • @gui.ferreira
      @gui.ferreira  5 หลายเดือนก่อน

      That is one of the Advantages of using Testcontainers directly since it has wait strategies in place.
      For the cases you mentioned, if you are using FluentDocker, you can Wait for an HTTP response. Both Kafka and Rabbit can expose an HTTP Port