springboot jpa 测试小例子

瘦欲@ 提交于 2020-02-28 14:30:54

在比较大型的项目中,我们需要在开发之前,进行某些模块的先行测试,这就用到了springboot中单元测试工具了
下面我们通过一个小案例,来讲解下如何利用Junit测试工具进行jpa开发的测试

测试代码我们要存放到test包下
在这里插入图片描述
这个数据库连接以及jpa的配置
在这里插入图片描述
我们利用接口继承jpa实现类
在这里插入图片描述

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
以上是maven工程依赖配置
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!