广告
返回顶部
首页 > 资讯 > 后端开发 > Python >springboottest测试依赖和使用方式
  • 275
分享到

springboottest测试依赖和使用方式

2024-04-02 19:04:59 275人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

目录SpringBoottest测试依赖和使用创建测试类Maven无法使用spring test注解看pom.xml中是否已经引入了spring test的依赖springboott

springboottest测试依赖和使用

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
</dependency>

创建测试类

注意加运行启动注解,和springbootest注解

@RunWith(SpringRunner.class)
@SpringBootTest
public class User01MapperTest {
 
    @Autowired
    User01Mapper user01Mapper;
 
    @Test
    public void testQuery(){
        User01 user = user01Mapper.selectByPrimaryKey("张三");
        System.out.println(user);
    }
}

maven无法使用spring test注解

看pom.xml中是否已经引入了spring test的依赖

如果没有,加入以下依赖

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.1.3.RELEASE</version>
</dependency>

注意:加入新的依赖后,要maven->update project,导入一下spring-test的jar

如果已经有依赖了,还是不能使用Spring-test的注解,那么看看libraries中的spring-test.jar包,如果是黑色的,如下图。

把依赖中的test去掉,test表示只能在src下的test文件夹使用。

<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-test</artifactId>
	<version>4.1.3.RELEASE</version>
	<!-- <scope>test</scope> -->
</dependency>

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: springboottest测试依赖和使用方式

本文链接: https://www.lsjlt.com/news/141655.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作