SpringBoot-integrated junit test class

Based on an article, we want to complete the test code, you need to open SpringbootMybatisApplicationTests, enter the corresponding address in the browser before test results show, here, we have to complete the integration by SpringBoot junit test class to another easier Method to test

1. Import the junit test dependency package

<!--测试的起步依赖-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

2. Writing test classes

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringbootMybatisApplication.class)
public class MybatisTest {

    @Autowired
    private UserMapper userMapper;

    @Test
    public void test(){
        List<User> users = userMapper.userList();
        System.out.println(users);
    }

}

Test result display:

 

 

Source code download:  https://pan.baidu.com/s/1WGsdz49g1XmqhMdS0789Ww

Guess you like

Origin blog.csdn.net/weixin_42629433/article/details/84845926