第一步:在pom.xml导坐标
<!-- spring整合junit-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
第二步:测试类添加注解
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:bean.xml")
第三步:di注入
@Autowired
IAccountService accountService;
测试类如图
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:bean.xml")
public class AccountTest {
@Autowired
IAccountService accountService;
@Test
public void testFindById(){
Account aaa = accountService.findAccountById(3);
System.out.println(aaa);
}
}