Skip to content

Commit e55b8fc

Browse files
authored
Merge pull request #310 from kazuki43zoo/gh-309
Add @ExtendWith(SpringExtension.class) on @mybatistest
2 parents 52cb599 + 1fb9075 commit e55b8fc

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

mybatis-spring-boot-test-autoconfigure/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
<groupId>org.springframework</groupId>
4949
<artifactId>spring-tx</artifactId>
5050
</dependency>
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter-api</artifactId>
54+
<optional>true</optional>
55+
</dependency>
5156
<dependency>
5257
<groupId>com.h2database</groupId>
5358
<artifactId>h2</artifactId>

mybatis-spring-boot-test-autoconfigure/src/main/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2017 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import org.junit.jupiter.api.extension.ExtendWith;
2627
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
2728
import org.springframework.boot.autoconfigure.SpringBootApplication;
2829
import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration;
@@ -34,17 +35,20 @@
3435
import org.springframework.context.annotation.ComponentScan.Filter;
3536
import org.springframework.core.annotation.AliasFor;
3637
import org.springframework.test.context.BootstrapWith;
38+
import org.springframework.test.context.junit.jupiter.SpringExtension;
3739
import org.springframework.transaction.annotation.Transactional;
3840

3941
/**
40-
* Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}
41-
* for a typical mybatis test. Can be used when a test focuses <strong>only</strong> on
42-
* mybatis-based components.
42+
* Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}(JUnit 4)
43+
* and {@code @ExtendWith(SpringExtension.class)}(JUnit 5) for a typical mybatis test.
44+
* Can be used when a test focuses <strong>only</strong> on mybatis-based components.
45+
* Since 2.0.1, If you use this annotation on JUnit 5, {@code @ExtendWith(SpringExtension.class)} can omit
46+
* on your test class.
4347
* <p>
4448
* Using this annotation will disable full auto-configuration and instead apply only
4549
* configuration relevant to mybatis tests.
4650
* <p>
47-
* By default, tests annotated with {@code @JdbcTest} will use an embedded in-memory
51+
* By default, tests annotated with {@code @MybatisTest} will use an embedded in-memory
4852
* database (replacing any explicit or usually auto-configured DataSource). The
4953
* {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} annotation can be used to
5054
* override these settings.
@@ -63,6 +67,7 @@
6367
@Documented
6468
@Inherited
6569
@BootstrapWith(SpringBootTestContextBootstrapper.class)
70+
@ExtendWith(SpringExtension.class)
6671
@OverrideAutoConfiguration(enabled = false)
6772
@TypeExcludeFilters(MybatisTypeExcludeFilter.class)
6873
@Transactional

mybatis-spring-boot-test-autoconfigure/src/site/xdoc/index.xml.vm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,30 @@ public class PingTests {
335335

336336
</subsection>
337337

338+
<subsection name="Using @MybatisTest on JUnit 5">
339+
<p>
340+
The <code>@MybatisTest</code> can be used on JUnit 5.
341+
</p>
342+
343+
<source><![CDATA[
344+
@ExtendWith(SpringExtension.class)
345+
@MybatisTest
346+
public class CityMapperTest {
347+
// ...
348+
}]]></source>
349+
350+
<p>
351+
Since 2.0.1, the <code>@ExtendWith(SpringExtension.class)</code> can omit as follow:
352+
</p>
353+
354+
<source><![CDATA[
355+
@MybatisTest
356+
public class CityMapperTest {
357+
// ...
358+
}]]></source>
359+
360+
</subsection>
361+
338362
<subsection name="Appendix A. Imported auto-configuration">
339363

340364
<p>

mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestCustomFilterIntegrationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2017 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,6 @@
3232
* @author Kazuki Shimizu
3333
* @since 1.2.1
3434
*/
35-
@ExtendWith(SpringExtension.class)
3635
@MybatisTest(includeFilters = @ComponentScan.Filter(Component.class), excludeFilters = @ComponentScan.Filter(Service.class))
3736
@TestPropertySource(properties = {
3837
"mybatis.type-aliases-package=org.mybatis.spring.boot.test.autoconfigure"

mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestIntegrationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015-2017 the original author or authors.
2+
* Copyright 2015-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,6 @@
4242
* @author wonwoo
4343
* @since 1.2.1
4444
*/
45-
@ExtendWith(SpringExtension.class)
4645
@MybatisTest
4746
@TestPropertySource(properties = {
4847
"mybatis.type-aliases-package=org.mybatis.spring.boot.test.autoconfigure",

0 commit comments

Comments
 (0)