JUnit测试
简介
JUnit 是用于编写和运行可重复的自动化测试的开源测试框架。
- 断言测试
[实操]hello-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("关闭数据库连接");
}
}
注解
- @Test
- @Before
- @BeforeClass
- @After
- @AfterClass
- @Ignore
断言
F2 定位下一个有问题的地点