宣言的なテスト
@DataSetと@ExpectedDataSetアノテーションを使用して、テストデータのセットアップと検証を定義できます。
@DataSetと@ExpectedDataSetアノテーションを使用して、テストデータのセットアップと検証を定義できます。
フレームワークがテストクラスとメソッド名に基づいてデータセットを自動検出します。
JUnit Jupiter、Spock、Kotestを完全サポート。Spring Boot統合も利用可能です。
CSVとTSVをサポート。シナリオフィルタリングにより複数のテストでデータセットを共有できます。
CLEAN_INSERT、INSERT、UPDATE、DELETE、TRUNCATEなどをサポート。テーブル順序のカスタマイズも可能です。
カスタムデータローダー、コンパレータ、操作ハンドラー用のサービスプロバイダーインターフェース(SPI)を提供します。
dependencies {
// BOMを使用(推奨)
testImplementation(platform("io.github.seijikohara:db-tester-bom:VERSION"))
// JUnit
testImplementation("io.github.seijikohara:db-tester-junit")
// または Spock
testImplementation("io.github.seijikohara:db-tester-spock")
// または Kotest
testImplementation("io.github.seijikohara:db-tester-kotest")
}dependencies {
// BOMを使用(推奨)
testImplementation platform('io.github.seijikohara:db-tester-bom:VERSION')
// JUnit
testImplementation 'io.github.seijikohara:db-tester-junit'
// または Spock
testImplementation 'io.github.seijikohara:db-tester-spock'
// または Kotest
testImplementation 'io.github.seijikohara:db-tester-kotest'
}<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.seijikohara</groupId>
<artifactId>db-tester-bom</artifactId>
<version>VERSION</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- JUnit -->
<dependency>
<groupId>io.github.seijikohara</groupId>
<artifactId>db-tester-junit</artifactId>
<scope>test</scope>
</dependency>
<!-- または Spock -->
<dependency>
<groupId>io.github.seijikohara</groupId>
<artifactId>db-tester-spock</artifactId>
<scope>test</scope>
</dependency>
<!-- または Kotest -->
<dependency>
<groupId>io.github.seijikohara</groupId>
<artifactId>db-tester-kotest</artifactId>
<scope>test</scope>
</dependency>
</dependencies>package com.example;
@ExtendWith(DatabaseTestExtension.class)
@DataSet // CSVからテストデータを読み込む
@ExpectedDataSet // データベースの状態を検証
class UserRepositoryTest {
@Test
void shouldCreateUser() {
userRepository.create(new User("john", "john@example.com"));
}
@Test
void shouldUpdateUser() {
userRepository.update(1L, new User("john", "john.doe@example.com"));
}
}package com.example
@DatabaseTest
@DataSet // CSVからテストデータを読み込む
@ExpectedDataSet // データベースの状態を検証
class UserRepositorySpec extends Specification {
def "should create user"() {
when:
userRepository.create(new User("john", "john@example.com"))
then:
noExceptionThrown()
}
def "should update user"() {
when:
userRepository.update(1L, new User("john", "john.doe@example.com"))
then:
noExceptionThrown()
}
}package com.example
@DataSet // CSVからテストデータを読み込む
@ExpectedDataSet // データベースの状態を検証
class UserRepositorySpec : AnnotationSpec() {
init {
extensions(DatabaseTestExtension(registryProvider = { registry }))
}
@Test
fun shouldCreateUser() {
userRepository.create(User("john", "john@example.com"))
}
@Test
fun shouldUpdateUser() {
userRepository.update(1L, User("john", "john.doe@example.com"))
}
}src/test/resources/
└── com/example/UserRepositoryTest/
├── users.csv # 準備データ([Scenario]列でフィルタリング)
└── expected/
└── users.csv # 期待される状態([Scenario]列でフィルタリング)src/test/resources/
└── com/example/UserRepositorySpec/
├── users.csv # 準備データ([Scenario]列でフィルタリング)
└── expected/
└── users.csv # 期待される状態([Scenario]列でフィルタリング)src/test/resources/
└── com/example/UserRepositorySpec/
├── users.csv # 準備データ([Scenario]列でフィルタリング)
└── expected/
└── users.csv # 期待される状態([Scenario]列でフィルタリング)期待値の検証が失敗した場合、DB Testerは詳細なYAML形式のエラーメッセージを提供します:
Assertion failed: 2 differences in USERS
summary:
status: FAILED
total_differences: 2
tables:
USERS:
differences:
- path: row_count
expected: 3
actual: 2
- path: "row[0].EMAIL"
expected: john@example.com
actual: john@test.com
column:
type: VARCHAR(255)
nullable: falseTIP
出力は有効なYAMLです。標準的なYAMLライブラリがCI/CD統合のためにこの出力を解析できます。
詳細はエラーハンドリングを参照してください。