diff --git a/mybatis-spring-boot-test-autoconfigure/pom.xml b/mybatis-spring-boot-test-autoconfigure/pom.xml index e45024e5e..7c209f145 100644 --- a/mybatis-spring-boot-test-autoconfigure/pom.xml +++ b/mybatis-spring-boot-test-autoconfigure/pom.xml @@ -48,6 +48,11 @@ org.springframework spring-tx + + org.junit.jupiter + junit-jupiter-api + true + com.h2database h2 diff --git a/mybatis-spring-boot-test-autoconfigure/src/main/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTest.java b/mybatis-spring-boot-test-autoconfigure/src/main/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTest.java index 2cfa70675..b42e94f35 100644 --- a/mybatis-spring-boot-test-autoconfigure/src/main/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTest.java +++ b/mybatis-spring-boot-test-autoconfigure/src/main/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; @@ -34,17 +35,20 @@ import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; import org.springframework.test.context.BootstrapWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; /** - * Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)} - * for a typical mybatis test. Can be used when a test focuses only on - * mybatis-based components. + * Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}(JUnit 4) + * and {@code @ExtendWith(SpringExtension.class)}(JUnit 5) for a typical mybatis test. + * Can be used when a test focuses only on mybatis-based components. + * Since 2.0.1, If you use this annotation on JUnit 5, {@code @ExtendWith(SpringExtension.class)} can omit + * on your test class. *

* Using this annotation will disable full auto-configuration and instead apply only * configuration relevant to mybatis tests. *

- * By default, tests annotated with {@code @JdbcTest} will use an embedded in-memory + * By default, tests annotated with {@code @MybatisTest} will use an embedded in-memory * database (replacing any explicit or usually auto-configured DataSource). The * {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} annotation can be used to * override these settings. @@ -63,6 +67,7 @@ @Documented @Inherited @BootstrapWith(SpringBootTestContextBootstrapper.class) +@ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(MybatisTypeExcludeFilter.class) @Transactional diff --git a/mybatis-spring-boot-test-autoconfigure/src/site/xdoc/index.xml.vm b/mybatis-spring-boot-test-autoconfigure/src/site/xdoc/index.xml.vm index 01c0acf49..61ed5bdc8 100644 --- a/mybatis-spring-boot-test-autoconfigure/src/site/xdoc/index.xml.vm +++ b/mybatis-spring-boot-test-autoconfigure/src/site/xdoc/index.xml.vm @@ -335,6 +335,30 @@ public class PingTests { + +

+ The @MybatisTest can be used on JUnit 5. +

+ + + +

+ Since 2.0.1, the @ExtendWith(SpringExtension.class) can omit as follow: +

+ + + + +

diff --git a/mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestCustomFilterIntegrationTest.java b/mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestCustomFilterIntegrationTest.java index 6e13e2d95..b44ef418d 100644 --- a/mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestCustomFilterIntegrationTest.java +++ b/mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestCustomFilterIntegrationTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,6 @@ * @author Kazuki Shimizu * @since 1.2.1 */ -@ExtendWith(SpringExtension.class) @MybatisTest(includeFilters = @ComponentScan.Filter(Component.class), excludeFilters = @ComponentScan.Filter(Service.class)) @TestPropertySource(properties = { "mybatis.type-aliases-package=org.mybatis.spring.boot.test.autoconfigure" diff --git a/mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestIntegrationTest.java b/mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestIntegrationTest.java index b67d888b2..f9fa75219 100755 --- a/mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestIntegrationTest.java +++ b/mybatis-spring-boot-test-autoconfigure/src/test/java/org/mybatis/spring/boot/test/autoconfigure/MybatisTestIntegrationTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,6 @@ * @author wonwoo * @since 1.2.1 */ -@ExtendWith(SpringExtension.class) @MybatisTest @TestPropertySource(properties = { "mybatis.type-aliases-package=org.mybatis.spring.boot.test.autoconfigure",