Spring Boot Testcontainers Sinhala Guide | Dockerized DB Integration Testing

Spring Boot Testcontainers Sinhala Guide | Dockerized DB Integration Testing

ආයුබෝවන් යාළුවනේ!

දන්නවනේ, software develop කරනකොට code ලියනවා වගේම ඒක හරියට වැඩ කරනවද කියලා බලන එකත් කොච්චර වැදගත්ද කියලා? ඒ කියන්නේ testing. Unit tests, integration tests, end-to-end tests කියලා ගොඩක් testing වර්ග තියෙනවා. හැබැයි, මේකෙන් අපිට නිතරම අභියෝගයක් වෙන එකක් තමයි integration testing, විශේෂයෙන්ම අපේ application එක database, message broker වගේ external services එක්ක සම්බන්ධ වෙනකොට.

ලංකාවේ අපි දන්නවනේ, project එකක වැඩ කරනකොට, "අනේ මගේ මැෂින් එකේ වැඩ කරනවා, එයාගේ එකේ නෑ!" වගේ ප්‍රශ්න කොච්චර එනවද කියලා. Database එකක් setup කරන එක, ඒකට data දාන එක, test එක ඉවර වුණාම ඒ data clean කරන එක... මේ හැම දේම හරිම කරදරකාරී වැඩක්. තව CI/CD pipelines වලදීත් මේ database setup එක හරිම අමාරුයි, කාලය නාස්ති කරන දෙයක්.

මේ හැම ප්‍රශ්නයකටම හොඳම විසඳුමක් තමයි අද අපි කතා කරන Testcontainers කියන්නේ. Testcontainers කියන්නේ මොකක්ද? සරලවම කිව්වොත්, ඒක Java library එකක්. මේකෙන් පුළුවන් අපේ tests වලට අවශ්‍ය database, message broker, web browser වගේ external dependencies Docker containers විදිහට, අපිට අවශ්‍ය වෙලාවට විතරක් හදලා දීලා, test එක ඉවර වුණාම අයින් කරන්න. හිතන්න, ඔයාලට තියෙනවා තාවකාලික කඩයක් දාන්න. වැඩේ ඉවර වුණාම ඒ කඩේ ගලවනවා වගේ තමයි මේක. කිසිම අවුලක් නෑ, ලොකු setup එකක් නෑ, clean කරන්නත් ඕන නෑ.

අද අපි මේ article එකෙන් බලමු Spring Boot application එකක් Testcontainers use කරලා, Dockerized database එකක් එක්ක integration test කරන්නේ කොහොමද කියලා. මේකෙන් ඔයාලගේ testing experience එක අලුත් මට්ටමකට ගේන්න පුළුවන් වෙයි කියලා මට විශ්වාසයි. එහෙනම්, අපි පටන් ගමුද?

Testcontainers කියන්නේ මොකක්ද? (What is Testcontainers?)

Testcontainers කියන්නේ open-source Java library එකක්. මේකේ ප්‍රධානම අරමුණ තමයි integration tests වලදී අපිට අවශ්‍ය external services (databases, message brokers like Kafka/RabbitMQ, web browsers like Selenium, caches like Redis, etc.) Docker containers විදිහට provide කරන එක. මේ containers අපේ tests run වෙන වෙලාවට විතරක් spin up වෙලා, tests ඉවර වුණාම automatically terminate වෙනවා.

සාමාන්‍යයෙන් integration tests ලියනකොට අපිට database එකක්, RabbitMQ instance එකක් වගේ දේවල් setup කරන්න වෙනවා. මේවා manualy setup කරන එකට ලොකු කාලයක් යනවා. ඒ වගේම, developer ගේ machine එකේ දාන database version එකයි, CI/CD server එකේ තියෙන database version එකයි වෙනස් වෙන්න පුළුවන්. එතකොට තමයි අර "it works on my machine" කියන සුප්‍රසිද්ධ ප්‍රශ්නේ එන්නේ. මේක solve කරන්න Testcontainers අපිට උදව් වෙනවා, මොකද, හැම වෙලාවෙම අපිට consistent environment එකක් ලැබෙන නිසා. Docker images කියන්නේ versioned වන නිසා, අපිට හරියටම අපිට අවශ්‍ය version එකක් choose කරන්න පුළුවන්. ඒ වගේම, මේ containers අපිට අවශ්‍ය වෙලාවට විතරක් හදන නිසා, අපේ local machine එකේ resource consumption එකත් අවම වෙනවා.

ප්‍රධාන වාසි:

  • Isolation: හැම test එකක්ම තමන්ගේම අලුත් container එකක් එක්ක run වෙන නිසා tests අතර dependency නැහැ. එක test එකක වෙනස්කම් තව test එකකට බලපාන්නේ නෑ. එක test එකකදී අපි database එකට data ටිකක් දැම්මොත්, ඊලඟ test එක run වෙනකොට ඒ data නැතිව, අලුත් database එකක් එක්ක පටන් ගන්නවා. මේකෙන් tests fail වෙන්නේ කලින් test එකේ data නිසා කියන ප්‍රශ්නය සම්පූර්ණයෙන්ම නැති වෙනවා.
  • Real Services: In-memory databases (like H2) කියන්නේ development වලට හොඳයි වුණාට, production එකේදී භාවිතා කරන actual database එකක (PostgreSQL, MySQL, MongoDB, Oracle) හැසිරීමෙන් වෙනස් වෙන්න පුළුවන්. Schema migrations, specific SQL dialect issues වගේ දේවල් in-memory DB එකකින් අහු වෙන්නේ නැහැ. Testcontainers use කරනකොට, අපි production එකේ භාවිතා කරන ඒ database version එකම, ඒ Docker image එකෙන්ම test කරන්න පුළුවන්. මේකෙන් production environment එකේ එන්න පුළුවන් ප්‍රශ්න කලින්ම හොයාගන්න පුළුවන්, deploy කරන්න කලින්ම.
  • Speed and Efficiency: Manual setup කිරීමේ අවශ්‍යතාවය නැති කරනවා. Containers ඉක්මනට spin up වෙනවා. Tests ඉවර වුණාම automatically clean up වෙනවා. මේකෙන් developers ලට tests run කරලා feedback ගන්න යන කාලය අඩු වෙනවා.
  • CI/CD Friendly: CI/CD pipelines වලදී external dependencies setup කරන එක හරිම පහසු වෙනවා. Docker install කරලා තියෙන ඕනෑම environment එකක Testcontainers use කරන්න පුළුවන්. මේකෙන් build pipelines stable සහ reliable වෙනවා.
  • Reproducibility: හැම developer කෙනෙක්ටම සහ CI/CD server එකටම එකම environment එකක් ලැබෙනවා. මේකෙන් "it works on my machine" ප්‍රශ්න නැති වෙනවා.

දැන් ඔයාලට හිතෙයි, මොකටද මේ හැම දේම? අපිට සාමාන්‍ය database එකක් use කරන්න බැරිද කියලා. පුළුවන්. හැබැයි එතකොට ඔයාට database එක manualy setup කරන්න වෙනවා, test data manage කරන්න වෙනවා, test ඉවර වුණාම database එක clean කරන්න වෙනවා. මේ හැම දේම Testcontainers අපිට automate කරලා දෙනවා. වැඩේ ටක් ගාලා කරගන්න පුළුවන්.

අපිව පටන් ගමු: Setup එක (Let's Get Started: The Setup)

Spring Boot application එකක් Testcontainers එක්ක test කරන්න කලින්, අපිට අවශ්‍ය dependency ටික project එකට add කරගන්න ඕනේ. අපි මේකේදී Maven project එකක් use කරමු.

පූර්ව අවශ්‍යතා (Prerequisites):

  • Java Development Kit (JDK) 11 හෝ ඊට ඉහළ.
  • Apache Maven (හෝ Gradle).
  • Docker Desktop (ඔබගේ operating system එකට අනුව install කරගන්න). Testcontainers වැඩ කරන්න Docker daemon එකක් අවශ්‍යයි.

Maven Dependencies:

ඔබගේ pom.xml file එකට පහත dependencies add කරන්න:

<dependencies>
    <!-- Spring Boot Starter Test -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- Spring Boot Starter Data JPA (for database interaction) -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!-- PostgreSQL Driver -->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- Testcontainers BOM (Bill of Materials) for version management -->
    <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>testcontainers-bom</artifactId>
        <version>1.19.7</version> <!-- Replace with latest version -->
        <type>pom</type>
        <scope>import</scope>
    </dependency>

    <!-- Testcontainers for JUnit Jupiter (if using JUnit 5) -->
    <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>junit-jupiter</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- Testcontainers for PostgreSQL -->
    <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>postgresql</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

මෙහිදී, testcontainers-bom එක භාවිතා කරන්නේ සියලුම Testcontainers dependencies වල version එක manage කරන්නයි. postgresql dependency එක අවශ්‍ය වෙන්නේ PostgreSQL database container එකක් handle කරන්නයි.

Dockerized Database එකක් එක්ක Test කරමු (Let's Test with a Dockerized Database)

දැන් අපි Spring Boot application එකක UserRepository එකක් PostgreSQL database එකක් එක්ක test කරන්නේ කොහොමද කියලා බලමු. අපි හිතමු අපිට මේ වගේ සරල User entity එකක් සහ UserRepository එකක් තියෙනවා කියලා:

// src/main/java/com/example/demo/entity/User.java
package com.example.demo.entity;

import jakarta.persistence.*;

@Entity
@Table(name = "users") // Renamed to avoid conflicts with reserved words in some DBs
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String email;

    public User() {}

    public User(String name, String email) {
        this.name = name;
        this.email = email;
    }

    // Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "User{" +
               "id=" + id +
               ", name='" + name + '\'' +
               ", email='" + email + '\'' +
               '}';
    }
}
// src/main/java/com/example/demo/repository/UserRepository.java
package com.example.demo.repository;

import com.example.demo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    User findByEmail(String email);
}

දැන් අපි මේ UserRepository එක test කරන්න Testcontainers use කරන integration test එකක් ලියමු.

// src/test/java/com/example/demo/repository/UserRepositoryIntegrationTest.java
package com.example.demo.repository;

import com.example.demo.entity.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import static org.assertj.core.api.Assertions.assertThat;

@DataJpaTest
@Testcontainers // Testcontainers enable කරන්න මේ annotation එක දාන්න ඕනේ
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) // Spring Boot in-memory DB එක use කරන එක නවත්වන්න
class UserRepositoryIntegrationTest {

    @Container // Testcontainers විසින් manage කරන container එක identify කරනවා
    static PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:15-alpine");

    @DynamicPropertySource // Container එක start වුනාම ඒකේ details Spring Boot එකට කියන්න මේක use කරනවා
    static void setDatasourceProperties(DynamicPropertyRegistry registry) {
        registry.add("spring.datasource.url", postgreSQLContainer::getJdbcUrl);
        registry.add("spring.datasource.username", postgreSQLContainer::getUsername);
        registry.add("spring.datasource.password", postgreSQLContainer::getPassword);
        registry.add("spring.jpa.hibernate.ddl-auto", () -> "create-drop"); // Test runs වලදී DB schema auto create කරන්න
    }

    @Autowired
    private UserRepository userRepository;

    @Test
    void testSaveUser() {
        User user = new User("Kamal Perera", "[email protected]");
        User savedUser = userRepository.save(user);

        assertThat(savedUser).isNotNull();
        assertThat(savedUser.getId()).isNotNull();
        assertThat(savedUser.getName()).isEqualTo("Kamal Perera");
    }

    @Test
    void testFindByEmail() {
        User user = new User("Nimali Fernando", "[email protected]");
        userRepository.save(user);

        User foundUser = userRepository.findByEmail("[email protected]");

        assertThat(foundUser).isNotNull();
        assertThat(foundUser.getName()).isEqualTo("Nimali Fernando");
    }
}

මේ code එකේ වෙන්නේ මොනවද කියලා පැහැදිලි කරමු:

  • @DataJpaTest: මේක Spring Boot testing annotation එකක්. ඒක JPA components (repositories) tests කරන්න අවශ්‍ය Spring context එක load කරනවා.
  • @Testcontainers: JUnit 5 extension එකක්. මේකෙන් Testcontainers life-cycle manage කරනවා. මේ class එකේ තියෙන @Container annotations එක්ක වැඩ කරනවා.
  • @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE): සාමාන්‍යයෙන් @DataJpaTest එක Spring Boot test වලදී in-memory H2 database එකක් auto-configure කරනවා. ඒක නවත්වලා, අපේ Testcontainers database එක use කරන්න කියලා මේකෙන් කියනවා.
  • @Container static PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:15-alpine");:
    • මෙහිදී අපි PostgreSQL container එකක් define කරනවා. "postgres:15-alpine" කියන්නේ Docker image එකේ නමයි. ඔබට අවශ්‍ය නම් වෙනත් version එකක් හෝ database එකක් (e.g., MySQLContainer("mysql:8.0")) භාවිතා කරන්න පුළුවන්.
    • static කියලා දාන්නේ මේ container එක class එකේ හැම test method එකකටම share කරන්නයි. නැත්නම් හැම test එකකටම අලුත් container එකක් හැදෙනවා, ඒක ටිකක් slow වෙන්න පුළුවන්.
    • @Container annotation එකෙන් Testcontainers ට කියනවා මේ field එක container එකක් කියලා, ඒක manage කරන්න කියලා.
  • @DynamicPropertySource static void setDatasourceProperties(DynamicPropertyRegistry registry):
    • මේ method එක ඉතාම වැදගත්. Testcontainers විසින් container එකක් spin up කලාට පස්සේ, ඒ container එකේ database URL, username, password වගේ details random ports සහ credentials එක්ක generate කරනවා.
    • මේ method එකෙන් කරන්නේ ඒ dynamically generate වෙන properties ටික Spring Boot application context එකට supply කරන එකයි. ඒකෙන් Spring Boot app එකට පුළුවන් මේ temporary database එකට connect වෙන්න.
    • spring.jpa.hibernate.ddl-auto property එක create-drop විදිහට set කරලා තියෙන්නේ, හැම test run එකකදිම JPA හරහා database schema එක create කරලා, test ඉවර වුණාම drop කරන්නයි. මේකෙන් test isolation තව වැඩි වෙනවා.
  • @Autowired private UserRepository userRepository;: අපි test කරන්න යන Repository එක inject කරගන්නවා.
  • @Test methods: සාමාන්‍ය JUnit tests වගේම තමයි. Users save කරලා retrieve කරන operations test කරනවා.

මේ test එක run කරනකොට, මුලින්ම Testcontainers විසින් Docker daemon එකට කතා කරලා postgres:15-alpine image එකෙන් අලුත් container එකක් හදනවා. ඒ container එක start වුණාට පස්සේ, ඒකේ details Spring Boot context එකට දෙනවා. ඊට පස්සේ අපේ tests run වෙනවා. Tests ඉවර වුණාම container එක automatically stop වෙලා remove වෙනවා. අප්පේ, මේක එච්චර අමාරු දෙයක් නෙමෙයි!

Testcontainers වල වාසි සහ Hacks (Advantages and Hacks of Testcontainers)

Testcontainers වල ප්‍රධාන වාසි අපි කලින් කතා කළා. තවත් පොඩි "hacks" ටිකක් කියන්නම්, ඔයාලගේ testing experience එක තව වැඩි දියුණු කරගන්න.

ප්‍රධාන වාසි කෙටියෙන් නැවත:

  • Real Database Testing: In-memory DBs වලට වඩා production environment එකට සමාන environment එකක test කරන්න පුළුවන්. ඒකෙන් "development environment එකේ වැඩ කළා, production එකේ අවුල්" කියන ප්‍රශ්න අඩු කරනවා. Schema migrations, specific SQL dialect issues වගේ දේවල් in-memory DB එකකින් අහු වෙන්නේ නැහැ. Testcontainers use කරනකොට, අපි production එකේ භාවිතා කරන ඒ database version එකම, ඒ Docker image එකෙන්ම test කරන්න පුළුවන්. මේකෙන් production environment එකේ එන්න පුළුවන් ප්‍රශ්න කලින්ම හොයාගන්න පුළුවන්, deploy කරන්න කලින්ම.
  • Enhanced Test Isolation: හැම test එකකටම අලුත්, clean database instance එකක් ලැබෙන නිසා test order එක හෝ previous test executions වල data මත කිසිම dependency එකක් නෑ. එක test එකකදී අපි database එකට data ටිකක් දැම්මොත්, ඊලඟ test එක run වෙනකොට ඒ data නැතිව, අලුත් database එකක් එක්ක පටන් ගන්නවා. මේකෙන් tests fail වෙන්නේ කලින් test එකේ data නිසා කියන ප්‍රශ්නය සම්පූර්ණයෙන්ම නැති වෙනවා.
  • Faster Developer Feedback: Manual DB setup සහ cleanup නැති නිසා developers ලට ඉක්මනට tests run කරලා feedback ගන්න පුළුවන්.
  • CI/CD Pipeline Integration: Docker support කරන ඕනෑම CI/CD system එකක Testcontainers ඉතා පහසුවෙන් integrate කරන්න පුළුවන්. මේකෙන් build pipelines stable සහ reliable වෙනවා.

වැදගත් Hacks සහ Tips:

  1. Container Reusability:අපි කලින් test එකේ static keyword එක use කළා වගේ, සමහර වෙලාවට tests අතර container එක reuse කරන්න අවශ්‍ය වෙන්න පුළුවන්. මේකෙන් benefits දෙකක් තියෙනවා: එකක් තමයි container එකක් spin up කරන්න යන කාලය save වෙන නිසා tests run වෙන overall time එක අඩු වෙනවා. දෙවනි එක තමයි, Docker daemon එකට එන requests ගාන අඩු වෙනවා.හැබැයි, මේකෙන් test isolation නැති වෙන්න පුළුවන්. ඒ කියන්නේ, කලින් run වුණ test එකක data, ඊළඟ test එකට බලපාන්න පුළුවන්. මේක වළක්වන්න, test reusability අවශ්‍ය නම්, @Testcontainers(disabledWithoutDocker = true) වගේ දේවල් එක්ක @Container එකට static දාලා use කරන්න. ඒ වගේම, හැම test method එකකටම කලින් database state එක clean කරන්න, @BeforeEach වගේ එකකදී TRUNCATE TABLE queries දාන්න පුළුවන්. උදාහරණයක් විදිහට, userRepository.deleteAll(); වගේ command එකක් run කරන්න පුළුවන්. මේකෙන් performance එකයි test isolation එකයි අතර balance එකක් maintain කරන්න පුළුවන්.
  2. Testcontainers Cloud (Beta):ලොකු projects වල, Testcontainers localy run කරන එක resources (CPU, RAM) consumption එක වැඩි කරන්න පුළුවන්. විශේෂයෙන්ම tests ගොඩක් තිබ්බොත්, එකපාරට containers ගොඩක් run වෙනකොට machine එක slow වෙන්න පුළුවන්. ඒ වගේම Docker Desktop setup එකත් සමහර වෙලාවට කරදරයක් වෙන්න පුළුවන්. මේකට විසඳුමක් විදිහට Testcontainers Cloud කියන service එක ඇවිත් තියෙනවා. මේකෙන් containers cloud එකේ run කරන්න පුළුවන්, local resources save කරලා. මේක තවම beta stage එකේ තියෙනවා වුණත්, අනාගතයේදී මේක integration testing වලට විශාල පහසුවක් වෙයි කියලා හිතන්න පුළුවන්.

GenericContainer for Other Services:Testcontainers වලට built-in modules නැති Docker images (e.g., ඔබ විසින් develop කරන ලද custom microservices, third-party specific tools, or even a localstack for AWS services) test කරන්න GenericContainer class එක භාවිතා කරන්න පුළුවන්. මේක ඉතා බලවත් feature එකක්. මේකෙන් ඕනෑම Docker image එකක් spin up කරන්න පුළුවන්, ඒකට අවශ්‍ය configurations (ports, environment variables, commands) ලබා දීලා.

@Container
static GenericContainer<?> myApp = new GenericContainer<>("my-custom-app:latest")
    .withExposedPorts(8080); // Expose port 8080

Customizing Containers:Testcontainers ඉතා flexible tool එකක්. ඔබට Dockerfile එකකින් build කරපු custom image එකක් හෝ database එකට specific environment variables, volume mappings, port mappings, command line arguments වගේ දේවල් set කරන්න අවශ්‍ය නම්, Testcontainers වලින් ඒක ඉතා පහසුවෙන් කරන්න පුළුවන්. උදාහරණයක් විදිහට, ඔබට test කරන්න විශේෂ database schema එකක් හෝ initial data set එකක් අවශ්‍ය නම්, withInitScript() method එකෙන් SQL script එකක් load කරන්න පුළුවන්. ඒ වගේම, withEnv() එකෙන් environment variables set කරන්න පුළුවන්, withExposedPorts() එකෙන් ports expose කරන්න පුළුවන්. මේ වගේ with... methods ගොඩක් තියෙනවා, ඔබට අවශ්‍ය විදිහට container එක customize කරන්න පුළුවන්.

@Container
static PostgreSQLContainer<?> customPostgres = new PostgreSQLContainer<>("postgres:15-alpine")
    .withDatabaseName("test_db")
    .withUsername("testuser")
    .withPassword("testpass")
    .withInitScript("sql/init_script.sql"); // Initial SQL script to run

@ServiceConnection (Spring Boot 3.1+):මේක Spring Boot 3.1 සහ ඊට ඉහළ versions වලට ආපු නියම feature එකක්. කලින් @DynamicPropertySource method එකක් ලියලා manualy properties set කරන්න ඕන වුණානේ. ඒ කරදරය දැන් නෑ! @ServiceConnection annotation එක විතරක් @Container field එකට add කලාම, Spring Boot විසින් Testcontainers container එකේ connection details (JDBC URL, username, password) auto-configure කරනවා. මේක වැඩේ තවත් පහසු කරනවා, boilerplate code අඩු කරනවා, සහ configuration errors ඇතිවෙන එක වලක්වනවා.උදාහරණයක්:

@ServiceConnection // Testcontainers විසින් හදන DB එකට Spring Boot auto-connect කරයි
static PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:15-alpine");

මේක PostgreSQLContainer, MySQLContainer, RedisContainer, KafkaContainer වගේ Testcontainers modules ගොඩකට support කරනවා. ඉතින්, ඔයා Spring Boot 3.1+ use කරනවා නම්, මේක తప్ప නොකර use කරන්න.

මේ hacks සහ tips ඔයාලගේ Spring Boot testing journey එක තවත් පහසු කරයි කියලා හිතනවා. මතක තියාගන්න, හොඳ tests කියන්නේ හොඳ software එකක පදනමයි.

නිගමනය (Conclusion)

හරි යාළුවනේ, අපි මේ article එකෙන් Testcontainers කියන්නේ මොකක්ද, ඒක Spring Boot application එකක් Dockerized database එකක් එක්ක test කරන්න use කරන්නේ කොහොමද, ඒ වගේම ඒකෙන් අපිට ලැබෙන වාසි මොනවද කියලා ගොඩක් දේවල් කතා කළා.

Testcontainers කියන්නේ integration testing වලදී අපිට මුහුණ දෙන්න වෙන ගොඩක් ප්‍රශ්න වලට හොඳ විසඳුමක්. Production environment එකට සමාන real databases එක්ක tests run කරන්න පුළුවන් වීම, test isolation, CI/CD pipelines වලට පහසුවෙන් integrate කරන්න පුළුවන් වීම වගේ ගොඩක් වාසි මේකෙන් ලැබෙනවා. මේක නිකන්ම testing tool එකක් නෙමෙයි, quality software develop කරන්න උදව් වෙන game-changer එකක්!

ඔයාලත් මේක try කරලා බලන්න. ඔයාලගේ project එකට Testcontainers integrate කරලා බලන්න. මොනවා හරි ප්‍රශ්න තියෙනවා නම්, comment section එකේ අහන්න. මට පුළුවන් විදිහට උදව් කරන්නම්. තවත් මෙවැනි වැදගත් ලිපියකින් හමුවෙමු!

සුභ දවසක්!