方法很简单:
1. 首先RunWith指定是用Spring的Unit Test
2. ContextConfiguration指定读取Spring 配置
3.
TransactionConfiguration指定Transaction的管理,defaultRollBack指定数据不回滚,默认是true,
跑完case后数据回滚。
@Test
用于标记TestCase
以下列举出了主要的annotation。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "application-context.xml" })
@TransactionConfiguration(transactionManager = "transactionManager",
defaultRollback=false)
public class BaseTest extends
AbstractDependencyInjectionSpringContextTests {
@Autowired
protected TestDao dao;
@BeforeTransaction
public void verifyInitialDatabaseState() {}
// set up test data within the transaction
@Before
public void setUpTestDataWithinTransaction() {}
@Test
// overrides the class-level defaultRollback setting
@Rollback(true)
public void modifyDatabaseWithinTransaction() {}
// execute "tear down" logic within the transaction
@After
public void tearDownWithinTransaction() {}
// logic to verify the final state after transaction has rolled
back
@AfterTransaction
public void verifyFinalDatabaseState() {}
@Test
// logic which does not modify database state
@NotTransactional
public void performNonDatabaseRelatedAction() {}
}
分享到:
相关推荐
NULL 博文链接:https://gavin2lee.iteye.com/blog/2052929
springboot-reactjs-fullstack ...使用Srping Boot和React js(React Hooks,Functional Programming,Spring Boot RESTful API,WEBPACK,BABEL JPA UNIT TEST和JEST TEST RUNNER)创建一个全栈应用程序
spring-mock.jar It's good for spring unit test.
使用JUnit和Mockito进行Spring RESTful的完整性和模拟测试 这是一个Spring Boot Maven演示应用程序,展示了如何使用JUnit和Mockito Framework对Sprig Boot RESTful服务执行完整性和模拟测试。 先决条件 Java SE开发...
Finally, you will learn how to use the Spring MVC test framework to unit test and integration test your REST API. After reading this book, you will come away with all the skills to build ...
CloudTest is a redefined unit testing approach and methodology, which can make your testing jobs become much more easy and efficient. It is a pure java lightweight framework integrated test cases ...
Unit tests Component tests Running tests with an in-memory database Handling HTTP clients and service discovery Implementing sample tests Integration tests Categorizing tests Capturing HTTP traffic ...
Improve performance of your applications with the new HTTP 2.0 standards. You’ll learn techniques to deal with security in Spring and discover how to implement unit and integration test strategies....
This book will provide you with the skills you need to successfully build and maintain meaningful unit and integration test cases for Spring Framework code. This book starts with a brief introduction...
主要介绍了Spring Boot从Controller层进行单元测试的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Secure your developments with easy-to-write, reliable unit and end-to-end tests Deploy your application on the cloud for free and invite the whole world to see 作者简介 · · · · · · Geoffroy ...
Spring Boot +单元测试+ Mockito + MVC-用于控制器和服务层
CloudTest is a redefined unit testing approach and methodology, which can make your testing jobs become much more easy and efficient. It is a pure java lightweight framework integrated test cases ...
#Spring Batch 示例 我学习 Spring Batch 的代码集合(带注释)。 我故意选择不使用Spring Boot,...##Unit test 包括 jacoco 测试覆盖率报告 gradle unitTest 测试报告将出现在以下目录中: build/reports/tests/in
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
这是一个由学生创建的项目,它与2009年Spring学期的德克萨斯大学CS307课程一起提供。它是协助开发家庭作业解决方案的框架。
unittest兼容的测试位于文件中,可以从命令行轻松执行: $ python test_unittest.py F... ====================================================================== FAIL: test_failing (__main__.TestCompare) --...
以'j'开头的项目基于Java 有些项目不包含 UNIT TEST 但包含 groovy 脚本。 ###01 - 弹簧容器项目: 01-spring-container 这个项目涵盖了基本的 spring 容器,有一些变化,比如: 标准 Bean 定义使用注解使用配置...
This project based on Spring Boot and there are examples includes: JPA Redis & MySQL Spring & JPA Listener Test(Unit Test/Integration Test) 跑测试时请stop掉本地mysql与redis
工作状态unit-test-1.4 unit-test-1.5 unit-test-2.0 unit-test-2.1 deploy什么是自动重配置? 自动重新配置包括三个部分。 它将cloud配置文件添加到Spring的活动配置文件列表中它将Cloud Foundry提供的所有属性...