springboottest测试依赖和使用方式

这篇文章主要介绍了springboottest测试依赖和使用方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

springboottest测试依赖和使用

1
2
3
4
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
</dependency>

创建测试类

注意加运行启动注解,和springbootest注解文章源自设计学徒自学网-https://www.sx1c.com/39325.html

1
2
3
4
5
6
7
8
9
10
11
12
13
@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的依赖

如果没有,加入以下依赖文章源自设计学徒自学网-https://www.sx1c.com/39325.html

1
2
3
4
5
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.1.3.RELEASE</version>
</dependency>

注意:加入新的依赖后,要maven->update project,导入一下spring-test的jar包文章源自设计学徒自学网-https://www.sx1c.com/39325.html

如果已经有依赖了,还是不能使用Spring-test的注解,那么看看libraries中的spring-test.jar包,如果是黑色的,如下图。文章源自设计学徒自学网-https://www.sx1c.com/39325.html

springboottest测试依赖和使用方式 -1文章源自设计学徒自学网-https://www.sx1c.com/39325.html

把依赖中的test去掉,test表示只能在src下的test文件夹使用。文章源自设计学徒自学网-https://www.sx1c.com/39325.html

1
2
3
4
5
6
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.1.3.RELEASE</version>
    <!-- <scope>test</scope> -->
</dependency>

以上为个人经验,希望能给大家一个参考。文章源自设计学徒自学网-https://www.sx1c.com/39325.html 文章源自设计学徒自学网-https://www.sx1c.com/39325.html

继续阅读
我的微信
微信扫一扫
weinxin
我的微信
惠生活福利社
微信扫一扫
weinxin
我的公众号
 
推荐应用
设计学徒自学网
  • 本文由 设计学徒自学网 发表于 2024年2月1日09:55:48
  • 转载请务必保留本文链接:https://www.sx1c.com/39325.html
    本站展示的所有图文软件均来自于互联网,仅用于软件学习研究分享传递,请勿商用,本站如有侵权请联系客服删除。
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证