Springboot使用junit

1. 首先要下载配套的spring-boot-starter-test包,注意版本要对应。

compile("org.springframework.boot:spring-boot-starter-web:2.0.2.RELEASE")

// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test
testCompile 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();
    }

}

猜你喜欢

转载自www.cnblogs.com/yoyotl/p/9185044.html