SpringBoot單元測試類創建

自己創建一個單元測試類遇到的坑:注入service並調用增刪改查:

import com.demo.DemoApplication;
import com.demo.entity.Eth;
import com.demo.service.IEthService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;


/**
 * Created by NanTian
 * on 2019/11/27 20:51
 */
@SpringBootTest(classes = DemoApplication.class)
public class EthTest {

    @Resource
    private IEthService iEthService;

    /**
     * 插入測試:insert
     */
    @Test
    public void Test1(){
        Eth eth = new Eth();
        eth.setId(120)
;        eth.setStuName("xiaoming");
        eth.setStuNumber("120");
        eth.setAge(11);
        boolean b = iEthService.insert(eth);
        System.out.println("結果是:"+b);
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章