{"id":14935,"date":"2023-01-27T11:40:00","date_gmt":"2023-01-27T06:10:00","guid":{"rendered":"https:\/\/blogrevamp.cashfree.com\/?p=14935"},"modified":"2023-01-27T12:06:05","modified_gmt":"2023-01-27T06:36:05","slug":"how-cashfree-simplified-integration-testing","status":"publish","type":"post","link":"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/","title":{"rendered":"Testcontainers for the Win! How Cashfree Simplified Integration Testing"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #005c31;color:#005c31\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #005c31;color:#005c31\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/#About_Testcontainers\" >About Testcontainers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/#Test_Scenario\" >Test Scenario<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/#Code\" >Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/#Continuous_Integration\" >Continuous Integration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/#But_why_do_we_need_Testcontainers\" >But why do we need Testcontainers?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/#What_is_next_for_us\" >What is next for us?<\/a><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">One of our primary goals at Cashfree Payments is to build products with the best in class quality. We rely on a lot of test automation to achieve this. Integration testing as part of this automation is done to verify that multiple modules developed separately, work together as expected. In this blog, we explain how we are using <a href=\"https:\/\/www.testcontainers.org\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Testcontainers<\/a> to ensure that our integration tests are easy to write and maintain as well as portable and reliable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"About_Testcontainers\"><\/span><strong>About Testcontainers<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The modules for which we write integration tests often depend on external resources. These include databases, caches, message queues, other cloud services, etc. which our tests need to take into account. The <a href=\"https:\/\/github.com\/testcontainers\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Testcontainers library<\/a> has the ability to manage the lifecycle of such external resources in the form of docker containers. It is open source and has support for multiple programming languages including Java, Go, Python, and more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using this library, we can set up and run the required dependencies\u2019 docker containers before our test execution starts. The module to be tested that has these dependencies connects to these docker containers (or testcontainers) and then our tests are run on top of this setup. After the test execution, we can gracefully tear down this setup. All of this can be accomplished with very few lines of code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-test-scenario\"><span class=\"ez-toc-section\" id=\"Test_Scenario\"><\/span><strong>Test Scenario<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s take an example where the requirement is to test an asynchronous consumer of a message queue. Consumer reads payment events from an AWS SQS queue and for a given payment event, it updates the corresponding order\u2019s status in MySQL DB and finally deletes the event from the queue. So, we can write an integration test for this consumer by spawning two testcontainers &#8211; MySQL and <a href=\"https:\/\/github.com\/localstack\/localstack\">Localstack<\/a> (for AWS SQS) and configuring the consumer code to point to these testcontainers.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"770\" height=\"429\" data-attachment-id=\"14938\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/testcontainors_d1_v3\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D1_V3.png?fit=1729%2C962&amp;ssl=1\" data-orig-size=\"1729,962\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Testcontainors_D1_V3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D1_V3.png?fit=770%2C429&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D1_V3.png?resize=770%2C429&#038;ssl=1\" alt=\"\" class=\"wp-image-14938\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D1_V3.png?resize=1024%2C570&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D1_V3.png?resize=300%2C167&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D1_V3.png?resize=768%2C427&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D1_V3.png?resize=1536%2C855&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D1_V3.png?w=1729&amp;ssl=1 1729w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Code\"><\/span><strong>Code<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The test code below is written in Java programming language. The payment event consumer is part of a Spring Boot application and we have written a JUnit integration test for it with the help of the Testcontainers library.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We first create a base abstract test class that can be inherited by other integration tests. In this base class, we create static instances of the testcontainers (MySQL and Localstack) that can be initiated before the test execution starts. We do this so that they can be reused across all the integration tests and the cost of reinitiating them before each test or test class can be avoided.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"770\" height=\"481\" data-attachment-id=\"14940\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/testcontainors_d2v2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D2V2.png?fit=1727%2C1080&amp;ssl=1\" data-orig-size=\"1727,1080\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Testcontainors_D2V2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D2V2.png?fit=770%2C481&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D2V2.png?resize=770%2C481&#038;ssl=1\" alt=\"\" class=\"wp-image-14940\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D2V2.png?resize=1024%2C640&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D2V2.png?resize=300%2C188&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D2V2.png?resize=768%2C480&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D2V2.png?resize=1536%2C961&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D2V2.png?w=1727&amp;ssl=1 1727w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The child class is responsible to execute the actual test once the testcontainers are up. Before the test is run, we set up an SQS queue and seed data in it by producing a message and also seed existing order data in MySQL DB.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"770\" height=\"481\" data-attachment-id=\"14942\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/testcontainors_d3v2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D3V2.png?fit=1727%2C1080&amp;ssl=1\" data-orig-size=\"1727,1080\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Testcontainors_D3V2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D3V2.png?fit=770%2C481&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D3V2.png?resize=770%2C481&#038;ssl=1\" alt=\"\" class=\"wp-image-14942\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D3V2.png?resize=1024%2C640&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D3V2.png?resize=300%2C188&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D3V2.png?resize=768%2C480&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D3V2.png?resize=1536%2C961&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D3V2.png?w=1727&amp;ssl=1 1727w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This code creates an SQS client instance from the localstack container.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"169\" data-attachment-id=\"14944\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/testcontainors_d4v2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D4V2.png?fit=1727%2C379&amp;ssl=1\" data-orig-size=\"1727,379\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Testcontainors_D4V2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D4V2.png?fit=770%2C169&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D4V2.png?resize=770%2C169&#038;ssl=1\" alt=\"\" class=\"wp-image-14944\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D4V2.png?resize=1024%2C225&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D4V2.png?resize=300%2C66&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D4V2.png?resize=768%2C169&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D4V2.png?resize=1536%2C337&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D4V2.png?w=1727&amp;ssl=1 1727w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The test asserts that the order status is updated as per the payment event and the queue is empty after the event is consumed. This completes our integration test.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"481\" data-attachment-id=\"14947\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/testcontainors_d5v2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D5V2.png?fit=1727%2C1080&amp;ssl=1\" data-orig-size=\"1727,1080\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Testcontainors_D5V2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D5V2.png?fit=770%2C481&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D5V2.png?resize=770%2C481&#038;ssl=1\" alt=\"\" class=\"wp-image-14947\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D5V2.png?resize=1024%2C640&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D5V2.png?resize=300%2C188&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D5V2.png?resize=768%2C480&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D5V2.png?resize=1536%2C961&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D5V2.png?w=1727&amp;ssl=1 1727w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The testcontainers can be brought down in two ways:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>We leave this job to \u201cRyuk\u201d &#8211; a special container that is started by the library before the test execution starts that takes the responsibility of fail-safe cleanup of testcontainers after the JVM shuts down. This is how it is happening in the above example and hence, no code is required for the same.<\/li>\n\n\n\n<li>We can disable Ryuk via system properties and can explicitly call the close() method on the testcontainers objects by adding a shutdown hook as shown below:<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"169\" data-attachment-id=\"14950\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/testcontainors_d6v2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D6V2.png?fit=1727%2C379&amp;ssl=1\" data-orig-size=\"1727,379\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Testcontainors_D6V2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D6V2.png?fit=770%2C169&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D6V2.png?resize=770%2C169&#038;ssl=1\" alt=\"\" class=\"wp-image-14950\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D6V2.png?resize=1024%2C225&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D6V2.png?resize=300%2C66&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D6V2.png?resize=768%2C169&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D6V2.png?resize=1536%2C337&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors_D6V2.png?w=1727&amp;ssl=1 1727w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Continuous_Integration\"><\/span><strong>Continuous Integration<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Our integration tests run as part of our CI pipeline which helps us identify issues and block unstable pull requests. This in turn reduces the turnaround time and fastens the feedback loop. Within a Kubernetes pod spawned by our CI pipeline, the containerised tests connect to a sidecar Docker runtime container to run the required Testcotnainers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, <a href=\"https:\/\/www.testcontainers.cloud\/\">Testcontainers Cloud<\/a> is now available and that removes the need to run the testcontainers depending on a sidecar Docker runtime container within any CI pipeline. The cloud solution can actually host the docker environment and run the testcontainers, we only need to point our tests to it. This helps keep the CI pipeline (or localhost testing) fast and lightweight.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"But_why_do_we_need_Testcontainers\"><\/span><strong>But why do we need Testcontainers?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are multiple reasons why:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1) Tests are more reliable. <\/strong>Integration tests often mock external dependencies with in-memory solutions which may not behave exactly like real dependencies. For example: Data types and native queries supported by databases like MySQL or Postgres used in production may differ from in-memory databases like H2. In such cases, Testcontainers are more reliable to test the exact behavior of any dependency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2) It is portable. <\/strong>Tests written using Testcontainers can run in any docker-compliant environment: localhost machines or CI pipelines. Write once and run anywhere. Test code is completely decoupled and has no impact on the development environment. Portability increases further with the Testcontainers Cloud solution. And hence, it requires less maintenance without sacrificing testing quality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3) Version upgrade of any external resource becomes very easy.<\/strong> Tests can be run against any dependency\u2019s newer version easily and verified if the application can safely be migrated to it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4) It is cheap. <\/strong>The cost of setting up a real \u201cproduction-like\u201d environment for integration tests can be high. For concurrent test runs, teams may need multiple such environments, increasing the cost and setup time further. With Testcontainers we can have test runs in different environments as close to reality as possible with minimal infra cost.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5) It requires less maintenance. <\/strong>Before the integration tests execution starts, generally, a clean set of resources (databases, caches, etc.) is required where data can be seeded based on the test scenario and after the execution data is cleaned up. This is easily achievable using Testcontainers as a new set of containers is spawned with every new run and we don\u2019t have any shared external resources that require state management. Multiple CI pipelines can run in parallel independent of each other without causing any race conditions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6) It is very easy to use.<\/strong> The Testcontainers library is simple and has a large set of predefined classes for different kinds of popular dependencies such as Redis, Kafka, Elasticsearch, different databases, cloud services, etc. It additionally provides a GenericContainer class that can help run any kind of dependency as long as it can be containerised. Hence, multiple test scenarios can be solved with ease.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>7) It makes all dependencies visible. <\/strong>When all the integration tests covering all the scenarios are in place, they give clear visibility to the developers over what all dependencies their complex service has in the form of testcontainers. This increases knowledge within the team and helps them work on new features with more pace, confidence, and predictability. This also helps us in onboarding any new engineer to the system, since they don\u2019t need to set up all dependencies on their own to run tests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>8) It has a minimal learning curve and it has support for multiple programming languages.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_next_for_us\"><\/span><strong>What is next for us?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">With Testcontainers we have been able to conveniently increase test automation for our services and cover different test scenarios. We started with Java services and now plan to start using it for our Golang services. Over time, we also plan to start using the Testcontainers Cloud solution which would enable us to test fast, reduce our localhost resource requirements (CPU, memory), and work with lightweight, cheaper machines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do our experiments in tech sound intriguing to you? If so, get in touch with us for some interesting opportunities for engineers like you!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.cashfree.com\/careers?utm_source=blog&amp;utm_medium=organic&amp;utm_campaign=testcontainers-for-win\/\" target=\"_blank\" rel=\"noopener\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"172\" data-attachment-id=\"13055\" data-permalink=\"https:\/\/blogrevamp.cashfree.com\/reporting-systems-to-ensure-enhanced-customer-satisfaction\/tech-blog\/\" data-orig-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2022\/10\/Tech-Blog.png?fit=1600%2C358&amp;ssl=1\" data-orig-size=\"1600,358\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Tech Jobs at Cashfree Payments\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2022\/10\/Tech-Blog.png?fit=770%2C172&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2022\/10\/Tech-Blog.png?resize=770%2C172&#038;ssl=1\" alt=\"Jobs at Cashfree Payments\" class=\"wp-image-13055\" srcset=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2022\/10\/Tech-Blog.png?resize=1024%2C229&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2022\/10\/Tech-Blog.png?resize=300%2C67&amp;ssl=1 300w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2022\/10\/Tech-Blog.png?resize=768%2C172&amp;ssl=1 768w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2022\/10\/Tech-Blog.png?resize=1536%2C344&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2022\/10\/Tech-Blog.png?w=1600&amp;ssl=1 1600w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>How cashfree simplified integration testing<\/p>\n","protected":false},"author":70,"featured_media":14954,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_themeisle_gutenberg_block_has_review":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_wpcom_ai_launchpad_first_post":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1497],"tags":[],"class_list":["post-14935","post","type-post","status-publish","format-standard","has-post-thumbnail","category-engineering"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Testcontainers for the Win! How Cashfree Simplified Integration Testing<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Testcontainers for the Win! How Cashfree Simplified Integration Testing\" \/>\n<meta property=\"og:description\" content=\"How cashfree simplified integration testing\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/\" \/>\n<meta property=\"og:site_name\" content=\"Cashfree Payments Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-27T06:10:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-27T06:36:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors-Integration-Testing-Cashfree-Payments.png?fit=1203%2C800&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1203\" \/>\n\t<meta property=\"og:image:height\" content=\"800\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Shubham Atlani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shubham Atlani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Testcontainers for the Win! How Cashfree Simplified Integration Testing","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/","og_locale":"en_US","og_type":"article","og_title":"Testcontainers for the Win! How Cashfree Simplified Integration Testing","og_description":"How cashfree simplified integration testing","og_url":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/","og_site_name":"Cashfree Payments Blog","article_published_time":"2023-01-27T06:10:00+00:00","article_modified_time":"2023-01-27T06:36:05+00:00","og_image":[{"width":1203,"height":800,"url":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors-Integration-Testing-Cashfree-Payments.png?fit=1203%2C800&ssl=1","type":"image\/png"}],"author":"Shubham Atlani","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Shubham Atlani","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/#article","isPartOf":{"@id":"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/"},"author":{"name":"Shubham Atlani","@id":"https:\/\/blogrevamp.cashfree.com\/#\/schema\/person\/65b6cbc8ee69c85df29a51cc18be474a"},"headline":"Testcontainers for the Win! How Cashfree Simplified Integration Testing","datePublished":"2023-01-27T06:10:00+00:00","dateModified":"2023-01-27T06:36:05+00:00","mainEntityOfPage":{"@id":"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/"},"wordCount":1263,"commentCount":0,"image":{"@id":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors-Integration-Testing-Cashfree-Payments.png?fit=1203%2C800&ssl=1","articleSection":["Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blogrevamp.cashfree.com\/how-cashfree-simplified-integration-testing\/","url":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/","name":"Testcontainers for the Win! How Cashfree Simplified Integration Testing","isPartOf":{"@id":"https:\/\/blogrevamp.cashfree.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/#primaryimage"},"image":{"@id":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors-Integration-Testing-Cashfree-Payments.png?fit=1203%2C800&ssl=1","datePublished":"2023-01-27T06:10:00+00:00","dateModified":"2023-01-27T06:36:05+00:00","author":{"@id":"https:\/\/blogrevamp.cashfree.com\/#\/schema\/person\/65b6cbc8ee69c85df29a51cc18be474a"},"breadcrumb":{"@id":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/#primaryimage","url":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors-Integration-Testing-Cashfree-Payments.png?fit=1203%2C800&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors-Integration-Testing-Cashfree-Payments.png?fit=1203%2C800&ssl=1","width":1203,"height":800},{"@type":"BreadcrumbList","@id":"https:\/\/www.cashfree.com\/blog\/how-cashfree-simplified-integration-testing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blogrevamp.cashfree.com\/"},{"@type":"ListItem","position":2,"name":"Engineering","item":"https:\/\/blogrevamp.cashfree.com\/category\/engineering\/"},{"@type":"ListItem","position":3,"name":"Testcontainers for the Win! How Cashfree Simplified Integration Testing"}]},{"@type":"WebSite","@id":"https:\/\/blogrevamp.cashfree.com\/#website","url":"https:\/\/blogrevamp.cashfree.com\/","name":"Cashfree Payments Blog","description":"Cashfree Payments- Payment Gateway for India","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blogrevamp.cashfree.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blogrevamp.cashfree.com\/#\/schema\/person\/65b6cbc8ee69c85df29a51cc18be474a","name":"Shubham Atlani","url":"https:\/\/blogrevamp.cashfree.com\/author\/shubhamatlani\/"}]}},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9MjXo-3ST","jetpack_likes_enabled":false,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blogrevamp.cashfree.com\/wp-content\/uploads\/2023\/01\/Testcontainors-Integration-Testing-Cashfree-Payments.png?fit=1203%2C800&ssl=1","_links":{"self":[{"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/posts\/14935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/users\/70"}],"replies":[{"embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/comments?post=14935"}],"version-history":[{"count":9,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/posts\/14935\/revisions"}],"predecessor-version":[{"id":14961,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/posts\/14935\/revisions\/14961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/media\/14954"}],"wp:attachment":[{"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/media?parent=14935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/categories?post=14935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogrevamp.cashfree.com\/wp-json\/wp\/v2\/tags?post=14935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}