Coding Shorts 108: Using TestContainers in .NET Core

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

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

  • @andreasgkizis2135
    @andreasgkizis2135 27 วันที่ผ่านมา

    Thanks a ton, very clear very nice and i am thankful for the public repo!

  • @n8wrl
    @n8wrl หลายเดือนก่อน +4

    Good to see you back Shawn!

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

    Services are not a part of DatabaseFixture. All we need is to up and run contaner to get connection string which will be passed to Services on the test class level.
    Here is what we did in our project .
    Separate static class for database container which has TestContainer MsSqlBuilder - it runs one db container per assembly via static reference
    DataBaseFixture - test class which creates a database with the name of T (separate database for every test class but in the same dbContainer)
    DatabseFixture InitializeAsync and DisposeAsync for Respawner CreateAsync/ResetAsync
    TestClass InitializeAsync - get dbEntity Faker, generate items, resolve DbContext - AddRange - SaveChanges(). When resolving dbContext Services already has connectionstring to dbContainer and nameof(T) as a Database name
    So in the end we have 1 container per assembly and every class of the assembly has its own database which is refreshed after every test method has run. It allows us to run all tests in parallel without any side effects

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

      Not a bad strategy. In xUnit 3 you'll be able to doing assembly-level fixtures which is essentially what you're doing.

  • @Joey-m8w
    @Joey-m8w หลายเดือนก่อน +1

    Thank you! Glad to have you back!

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

    Really useful. Thanks.
    By the way. Does this format here leads to a tricky scenario where one test may change the data in the database that other tests will see, right?
    I did something once that created a snapshot after publishing the database and restored this snapshot before each test.

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

      Depends on the scope, but yes. (Not a solution for unit tests). But you could scope the container to be rerun on every test, or use fixtures

  • @kenlee2540
    @kenlee2540 29 วันที่ผ่านมา

    Thanks Master Shawn, where can get the free SQL database hosting?

    • @swildermuth
      @swildermuth  29 วันที่ผ่านมา

      No where I know.

    • @kenlee2540
      @kenlee2540 28 วันที่ผ่านมา

      @@swildermuth 😅

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

    awesome

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

    That's good

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

    No source code for this 😅?

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

      Just added it to the description: github.com/shawnwildermuth/codingshorts/tree/main/testingwithcontainers

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

    Are you using a tool that removes all the pauses and gaps? I can see all the jumps in your face. It feels you're talking non stop for 15 minutes! I find this tiring when listening in this manner. Is the goal to make the video shorter? I don't mind if it's like 3 minutes longer if you're talking in a natural way. I noticed this trend with several TH-camrs. Ugh! Anyway, thanks for the tutorial.

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

      I have an editor work with me to take out the mistakes and some of the pauses. Usually the videos are 2-3x the length without the editing. We might be too aggresive on the removals. I'll look at that. Thanks for supporting the channel.