Spring整合junit

2019-11-10  本文已影响0人  dillqq

步骤1:导入spring整合junit的jar包(坐标)

<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.0.RELEASE</version>
<scope>test</scope>
</dependency>

步骤2:使用junit提供的注解把原有的main方法替换了,替换成Spring提供了。在测试类上加如下

@RunWith(SpringJUnit4ClassRunner.class)

步骤3:告知容器配置是注解还是xml的

使用注解创建

@ContextConfiguration(classes = Configurtion.class)

使用xml创建

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:bean.xml")
上一篇 下一篇

猜你喜欢

热点阅读