好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

springboottest测试依赖和使用方式

springboottest测试依赖和使用

?

1

2

3

4

< dependency >

    < groupId >org.springframework.boot</ groupId >

    < artifactId >spring-boot-starter-test</ artifactId >

</ dependency >

创建测试类

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

?

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的依赖

如果没有,加入以下依赖

?

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包

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

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

?

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://blog.csdn.net/dog_egg_/article/details/99543502

查看更多关于springboottest测试依赖和使用方式的详细内容...

  阅读:21次