Eclipse 中 使用 JUnit
1. 针对测试类(或接口)创建测试类
测试类(或接口)--> new --> JUnit Test Case
选取 New JUnit 4 test --> Next -->(选取接口方法) 点击 Finish
2. 编辑测试类 (完成测试类声明方法的具体实现)
1) 变量定义
为了提高变量的可重用性建议使用全局变量
2) 变量初始化(自定义)
3) 使用测试(使用整个测试类中的多个@Test 共同执行测试)
@Test 对方法的测试实现
@Before 模拟数据添加到数据库中(模拟数据接近真实)
@After 数据库中模拟数据的销毁
@Before 和 @After 中的数据准备工作由非测试借口完成(DAO 接口)
@BeforeClass 所使用接口的初始化(spring 容器的初始化)
@AfterClass 接口对象的销毁
注意:@Before 为 每一个@Test行为执行之前执行
@After 为 每一个@Test行为执行之后执行
假设有 n 个 @Test ,@Before 和 @After 将执行 n 次
@BeforeClass 和 @AfterClass 的执行顺序同上,但不同的是无论有多少的@Test @BeforeClass 和 @AfterClass 只执行一次,声明方法,变量为静态的
4) @Test 测试行为实现规范
测试方法针对虚拟数据测试
5) Fail and Error
Fail 表示测试失败
预期运行结果与实际单元运行结果不同导致
Error 表示测试错误
程序没有考虑到的情况,在断言之前就因某种错误引发例外而终止
分享到:
相关推荐
Whether you are new to JUnit testing and mocking or a seasoned Mockito expert, this book will provide you with the skills you need to successfully build and maintain meaningful JUnit test cases and ...
Whether you are new to JUnit testing and mocking or a seasoned Mockito expert, this book will provide you with the skills you need to successfully build and maintain meaningful JUnit test cases and ...
-- Be familiar with popular development tools, such as CVS, Ant, JUnit, etc -- Be familiar with popular web development frameworks and tools, such as Struts, Spring, Hibernate. -- Good knowledge of...
您将了解如何使用Spring注释-@ Autowired,@ Component,@ Service,@ Repository,@ Configuration,@ Primary...。 您将深入了解Spring MVC-DispatcherServlet,模型,控制器和ViewResolver 您将使用各种Sp
Create a RESTful web service with Spring Boot Use React for frontend programming Learn to create unit tests using JUnit Discover techniques to secure the backend using Spring Security Employ Material-...
网上的东西好大多都不能直接用,自己结合网上资料做了一个Struts2+Spring3+MyBatis3的测试工程,JUnit测试用例和WEB服务。 内涵完整jar包,解压直接可用,包括一个表文件。 Eclipse3.2+Tomcat/5.5+jdk1.5.0_17 - ...
AlarmManager and the Scheduled Service Pattern PowerManager and WakeLocks JobScheduler Accessing Location-Based Services The Fused Location Provider Working with the Clipboard Telephony Working With ...
Nginx_Window_Register_Service RESTFUL_architecture RabbitMQ RabbitMQ_User_Manager Redis_Config Redis_Monitor Redis_State_Live Scala_Java_Override_Variable_Parameter Scala_Map_List_Array Security_...
AlarmManager and the Scheduled Service Pattern PowerManager and WakeLocks JobScheduler Accessing Location-Based Services The Fused Location Provider Working with the Clipboard Telephony Working With ...
8.3.6. JUnit 3.8遗留支持 8.3.7. Spring TestContext Framework 8.3.8. PetClinic示例 8.4. 更多资源 II. 中间层数据访问 9. 事务管理 9.1. 简介 9.2. 动机 9.3. 关键抽象 9.4. 使用资源同步的事务 9.4.1...
8.3.6. JUnit 3.8遗留支持 8.3.7. Spring TestContext Framework 8.3.8. PetClinic示例 8.4. 更多资源 II. 中间层数据访问 9. 事务管理 9.1. 简介 9.2. 动机 9.3. 关键抽象 9.4. 使用资源同步的事务 9.4.1...