跳转到内容

单元测试

自动导入 MyBatis-Plus 测试所需相关配置,通过 @MybatisPlusTest 注解快速配置测试类。

示例工程

使用教程

  1. 添加测试依赖

    <dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter-test</artifactId>
    <version>3.5.9</version>
    </dependency>
  2. 编写测试用例

    import org.junit.jupiter.api.Test;
    import org.springframework.beans.factory.annotation.Autowired;
    import static org.assertj.core.api.Assertions.assertThat;
    @MybatisPlusTest
    class MybatisPlusSampleTest {
    @Autowired
    private SampleMapper sampleMapper;
    @Test
    void testInsert() {
    Sample sample = new Sample();
    sampleMapper.insert(sample);
    assertThat(sample.getId()).isNotNull();
    }
    }
Baomidou

© 2016-2024 Baomidou™. All Rights Reserved.

Power by Astro Starlight | Sponsored by JetBrains

渝ICP备2021000141号-1 | 渝公网安备50011302222097