• breadsmasher@lemmy.world
    link
    fedilink
    English
    arrow-up
    7
    ·
    3 months ago

    What is the specific use case of these, relating to unit testing?

    Why not just have the container execute unit tests, once that process ends and the container closes itself? This wouldn’t need anything additional.

    • akash_rawal@lemmy.worldOP
      link
      fedilink
      arrow-up
      4
      ·
      3 months ago

      I don’t get it, how would a database container run your unit tests? And unless you know some secret option to stop the database after, say, it is idle for a few seconds, it will continue running.

      The purpose is to test database dependent code by spinning up a real database and run your code against that.

      • breadsmasher@lemmy.world
        link
        fedilink
        English
        arrow-up
        14
        ·
        edit-2
        3 months ago

        Ah! That’s what I didn’t understand. So its not a container for executing unit tests. Its a container for dependencies to support unit tests. That is not clear from the readme unless I missed something

        edit - the title could be “Self terminating containers for real world dependencies to support your unit tests”

        • MagicShel@programming.dev
          link
          fedilink
          arrow-up
          11
          ·
          3 months ago

          This feels more like an integration test than a unit test to me. Maybe that’s not an important distinction to make, but it feels like it would also help communicate intent.

          • Adam@doomscroll.n8e.dev
            link
            fedilink
            English
            arrow-up
            12
            ·
            3 months ago

            I’m reading this scratching my head going “If your unit tests need a database they ain’t a unit test”.

        • akash_rawal@lemmy.worldOP
          link
          fedilink
          arrow-up
          2
          ·
          3 months ago

          Thanks man, my brain was short-circuited on Testcontainers so I couldn’t write better. Also I am stealing the title.

      • Miaou
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago

        So it’s not for unit tests, that’s where the confusion stems