Spring定位:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.23</version>
</dependency>
架构:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6583915993193788568f5438ea7b06b1.png)
源码:
package com.jin.service;
import com.jin.config.SpringConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class AccountTest {
@Autowired
private AccountService accountService;
@Test
public void findById(){
System.out.println(accountService.findById(1));
}
@Test
public void findAll(){
System.out.println(accountService.findAll());
}
}
总结:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6f10dda2776f216881bf53190544aa29.png)