MyBatis-Plus 快速入门-快速测试

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

添加测试依赖

Maven:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter-test</artifactId>
    <version>3.5.1</version>
</dependency>

Gradle:

compile group: com.baomidou, name: mybatis-plus-boot-starter-test, version: 3.5.1

编写测试用例

通过 ​@MybatisPlusTest​ 可快速编写 Mapper 对应的测试类,实现快速测试代码

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();
    }
}

作者:andy,如若转载,请注明出处:https://www.web176.com/mybatis-plus/20403.html

(0)
打赏 支付宝 支付宝 微信 微信
andy的头像andy
上一篇 2023年5月16日
下一篇 2023年5月16日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注