文章目錄
-
-
- 需要添加的注解
- 示例
-
需要添加的注解
1.在類上
@RunWith(SpringRunner.class)
@SpringBootTest(classes = 項目啟動類.class)//項目啟動類
2.方法上
3.注入
示例
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.junit.runner.RunWith;
import org.junit.Test;
/**
* @program: stock-service
* @ClassName: ss
* @version: 1.0
* @description:
* @author: zhaonian
* @create: 2020-03-09 10:23
**/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = StockServiceApplication.class)
public class ss {
@Autowired
private StockService stockService;
@Test
public void sss() {
System.out.println(stockService);
}
}