Skip to content

Commit

Permalink
Using testcontainers dev mode for junits (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Jun 15, 2023
1 parent 3443168 commit fedfe59
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/boot-data-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
build:

runs-on: ubuntu-latest

defaults:
run:
working-directory: "boot-data-redis"
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -27,13 +29,6 @@ jobs:
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Start up databases via Docker Compose
run: |
docker-compose up -d redis
sleep 5
docker ps -a
cache: 'maven'
- name: Build with Maven
run: |
cd boot-data-redis
mvn -B package --file pom.xml
run: ./mvnw -B package --file pom.xml
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
Empty file modified boot-data-redis/mvnw
100644 → 100755
Empty file.
10 changes: 10 additions & 0 deletions boot-data-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.test.web.reactive.server.WebTestClient;

@SpringBootTest
@Import(TestDemoApplication.class)
public class DemoApplicationTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class TestDemoApplication {

@Bean
@ServiceConnection(name = "redis")
GenericContainer<?> redisContainer() {
return new GenericContainer<>(DockerImageName.parse("redis").withTag("7.0.11"))
.withExposedPorts(6379);
}

public static void main(String[] args) {
SpringApplication.from(DemoApplication::main)
.with(TestDemoApplication.class)
.run(args);
}

}

0 comments on commit fedfe59

Please sign in to comment.