Skip to content

Commit

Permalink
Merge pull request #310 from kazuki43zoo/gh-309
Browse files Browse the repository at this point in the history
 Add @ExtendWith(SpringExtension.class) on @mybatistest
  • Loading branch information
kazuki43zoo authored Mar 30, 2019
2 parents 52cb599 + 1fb9075 commit e55b8fc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
5 changes: 5 additions & 0 deletions mybatis-spring-boot-test-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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 <strong>only</strong> 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 <strong>only</strong> 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.
* <p>
* Using this annotation will disable full auto-configuration and instead apply only
* configuration relevant to mybatis tests.
* <p>
* 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.
Expand All @@ -63,6 +67,7 @@
@Documented
@Inherited
@BootstrapWith(SpringBootTestContextBootstrapper.class)
@ExtendWith(SpringExtension.class)
@OverrideAutoConfiguration(enabled = false)
@TypeExcludeFilters(MybatisTypeExcludeFilter.class)
@Transactional
Expand Down
24 changes: 24 additions & 0 deletions mybatis-spring-boot-test-autoconfigure/src/site/xdoc/index.xml.vm
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,30 @@ public class PingTests {

</subsection>

<subsection name="Using @MybatisTest on JUnit 5">
<p>
The <code>@MybatisTest</code> can be used on JUnit 5.
</p>

<source><![CDATA[
@ExtendWith(SpringExtension.class)
@MybatisTest
public class CityMapperTest {
// ...
}]]></source>

<p>
Since 2.0.1, the <code>@ExtendWith(SpringExtension.class)</code> can omit as follow:
</p>

<source><![CDATA[
@MybatisTest
public class CityMapperTest {
// ...
}]]></source>

</subsection>

<subsection name="Appendix A. Imported auto-configuration">

<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e55b8fc

Please sign in to comment.