企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
## 步骤 1. 导包:spring-test.jar , spring-aop.jar , junit.jar 2. 告诉spring-unit配置文件的位置. 3. 告诉spring-junit谁加载配置文件. 4. 调用junit. ## 注意 当我们使用spring5版本的时候需要Junit的版本是4.12以上. ~~~ //告诉spring配置文件位置 @ContextConfiguration(value = "classpath:applicationContext.xml") //使用XML的方式 @ContextConfiguration(classes= SpringConfig.class) //使用配置类的方式 //告诉spring谁来加载配置文件 @RunWith(value = SpringJUnit4ClassRunner.class) public class Test { @Autowired private UserService userService; @org.junit.Test public void test1() { userService.save(); } } ~~~