location_city Bengaluru schedule Mar 19th 02:45 - 03:05 PM place Mysore Hall 3

How easy is it to write and maintain integration tests when the system under test interacts with databases and message stores? It can be quite challenging. The lack of control over the setup of databases can increase the cost of integration testing. Sometimes we take the route of using an in-memory database instead of the one we employ in the production environment, making the tests less effective. With docker containers, you can simplify this to some extent by running the setup before invoking your tests. Imagine if you get to control the database environment right from within the test code. TestContainers bring in this convenience.

Testcontainers is a Java library that you can invoke from your test code. It provides lightweight, throwaway instances of common databases, web browsers(Selenium tests), or anything else that can run in a Docker container.
 
 

Outline/Structure of the Demonstration

  • Demo 1: Using TestContainers for integration testing with real RDBMS (the one that you use in production) instead of using an in-memory database without sacrificing the flexibility.
  • Demo 2: Using TestContainers for tests driving your code that relies upon S3 API with Loclstack.

Learning Outcome

  • How Testcontainers simplify developing and maintaining integration tests
  • A tool that you can start using right away

Target Audience

Developers, Testers, Leads, Architects

Prerequisites for Attendees

Experience of developing and maintaining integration tests or having worked with such a team

schedule Submitted 5 months ago

Public Feedback

comment Suggest improvements to the Speaker
  • Naresh Jain
    By Naresh Jain  ~  1 month ago
    reply Reply

    Hi Naresha,

    Thank for you for submitting your proposal on TestContainers. This is an interesting topic.

    Can you please explain the context in which you used it? A snapshot of before and after.

    Also, assuming you've already implemented this, what specific outcomes did this help you achieve? If you can share some real data, this would be really useful.

    Thank you.

    • Naresha K .
      By Naresha K .  ~  1 month ago
      reply Reply

      Hi Naresh,

      Following are the two contexts which I used the testcontainers in.

      Usecase #1:

      Before: The application was using MySQL in production. We were using in-memory (H2) database for integration testing so that have better control over data setup and we don't have any overhead of infrastructure set up for running integration tests from CI. There were a few queries in IN clause which were working fine in H2 when passed with java null as argument, but failing when backed with MySQL. Using MySQL for integration testing would have been ideal, but were avoiding it due to the overhead associated with it.

      After: With testcontainers, we still retain all the flexibilities associated with the in-memory, and moving the infrastructure as close to production, helping us with quicker feedback.

      Usecase #2:

      We decided to use S3 for storing contents such as images and videos (dynamic content). We developed the feature by test driving on top of localstack + testcontainers. When we replaced localstack with AWS s3 in staging, it worked seamlessly. The CI runs these tests for every commit. The fact that we use testcontainers does not leak into CI setup/ configurations.

      Outcomes:

      1. Reduced cost of developing integration tests - encourages developers to write them
      2. Integration testing with an environment that is similar to the production

      Please let me know if you have clarifications/ follow up questions.

      • Naresh Jain
        By Naresh Jain  ~  3 weeks ago
        reply Reply

        Thanks for the clarification, Naresha. Would it be possible to demo the 2 use-cases in a 20-mins demo?

        • Naresha K .
          By Naresha K .  ~  3 weeks ago
          reply Reply

          Yes. I can do a 20 minutes demo around the use cases.

          • Naresh Jain
            By Naresh Jain  ~  2 weeks ago
            reply Reply

            Thank you. Please update your proposal.

            • Naresha K .
              By Naresha K .  ~  2 weeks ago
              reply Reply

              I have updated the proposal

  • Aino Corry
    By Aino Corry  ~  4 months ago
    reply Reply

    Hi Naresha, thank you for your submission. 

    Will you also be talking about the drawbacks of TestContainers?

    • Naresha K .
      By Naresha K .  ~  3 months ago
      reply Reply

      Hi Aino,

      I will touch upon the trade-offs such as container reuse, resource utilisation along with the examples. In my observation, the negative impacts are due to using the tool as a golden hammer - for example, with the availability of TestContainers, teams not writing unit tests and expecting faster feedback from integration tests. Please let me know if you had any specific aspect in your mind when you mentioned drawbacks.