1. 首先要下载配套的spring-boot-starter-test包,注意版本要对应。
compile("org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE")// Use JUnit test frameworktestImplementation 'junit:junit:4.12'// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-testtestCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.0.2.RELEASE'
2. 示例
@RunWith(SpringRunner.class)@SpringBootTest(classes = Springboot启动函数.class)public class NumberServiceT { @Autowired NumberService ns; @Test public void getNumberList() { // NumberService ns = new NumberService(); ns.getUseableNumber(); }}