spring boot -junit单元测试方法示例

package com.example.zs;

import com.example.zs.mapper.UserMapper;
import com.example.zs.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SpringBoot.class})
public class UserServiceTest {
    @Autowired
    private UserMapper userMapper;

    @Test
    public void inser() {
        User user = new User("name2",1);
        userMapper.insertUser(user);
    }
}
package com.example.zs;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBoot {
    public static void main(String[] args) {
        SpringApplication.run(springBoot.class,args);
    }
}

 

posted @ 2019-03-15 15:53  hcss  阅读(224)  评论(0编辑  收藏  举报