spring boot单元测试相关
在pom.xml中加入
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(locations = {“classpath:spring.xml”})
public class BaseTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
}
以最简单的 helloworld 为例,在测试类的类头部需要添加:@RunWith(SpringRunner.class) 和@SpringBootTest注解,在测试方法的顶端添加@Test即可,最后在方法上点击右键run就可以运行。 注:需要读取配置文件的引入 @ContextConfiguration(locations = {“classpath:spring.xml”}) 注解