JUnit 是用于编写和运行可重复的自动化测试的开源测试框架。
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

public class UserServiceTest {
    private UserService userService;
    @Before
    public void before(){
        System.out.println("初始化数据库连接");
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-context.xml");
        userService = (UserService) applicationContext.getBean("userService");
    }
    @Test
    public void testSayHi(){
        userService.sayHi();
    }
    @After
    public void after(){
        System.out.println("关闭数据库连接");
    }
}
F2 定位下一个有问题的地点
原文:https://www.cnblogs.com/hhhqqq/p/12582859.html