ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` 1. 添加依赖 添加spring-test 2. 通过@RunWith注解,指定spring的运行器 Spring的运行器是SpringJunit4ClassRunner 3. 通过@ContextConfiguration注解,指定spring运行器需要的配置文件路径 4. 通过@Autowired注解给测试类中的变量注入数据 ``` ### pom ``` <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.1.7.RELEASE</version> <scope>test</scope> </dependency> ``` ### 测试 ~~~ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:applicationContext.xml") public class testUserService { @Autowired private UserService userService; @Test public void testIoc(){ userService.saveUser(); } } ~~~