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);
    }
}

猜你喜欢

转载自www.cnblogs.com/hongchengshise/p/10537583.html