Skip to content

Commit

Permalink
Added Testcontainers to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert McNees committed Oct 3, 2023
1 parent a28f922 commit 0e47b8e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions complete/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:mongodb'
}

test {
Expand Down
15 changes: 15 additions & 0 deletions complete/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.data.domain.Example;

import com.example.accessingdatamongodb.Customer;
import com.example.accessingdatamongodb.CustomerRepository;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

@SpringBootTest
@Testcontainers
public class CustomerRepositoryTests {

@Container
@ServiceConnection
static MongoDBContainer container = new MongoDBContainer("mongo:7.0.2");

@Autowired
CustomerRepository repository;

Expand Down

0 comments on commit 0e47b8e

Please sign in to comment.