SpringBoot2.6+单元测试

SpringBoot老版本引入单元测试

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
....

@SpringBootTest
@RunWith(SpringRunner.class)
public class xxx{
    @Before
    public void setUp() throws Exception{
        ...
    }
}

SpringBoot升级后引入单元测试(标红加粗为与老版本差异部分)

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
....

@SpringBootTest
@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class xxx{
    @BeforeAll
    public void setUp() throws Exception{
        ...
    }
}

pom.xml配置文件不变

posted @ 2022-05-15 13:58  乱炖er  阅读(665)  评论(0编辑  收藏  举报