自己創建一個單元測試類遇到的坑:注入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);
}
}