springboottest测试依赖和使用方式

springboottest测试依赖和使用


    org.springframework.boot
    spring-boot-starter-test

创建测试类

注意加运行启动注解,和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的依赖

如果没有,加入以下依赖


    org.springframework
    spring-test
    4.1.3.RELEASE

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

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

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


	org.springframework
	spring-test
	4.1.3.RELEASE
	

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

你可能感兴趣的:(springboottest测试依赖和使用方式)