Unitils(http://www.unitils.org/summary.html)這個Java開源類包的目的是讓單元測試變得更加容易和可維護。Unitils構建在DBUnit與EasyMock項目之上並與JUnit和TestNG相結合。支持數據庫測試,支持利用mock對象進行測試並提供與Spring和Hibernate相集成。Unitils設計成以一種高度可配置和鬆散偶合的方式來添加這些服務到單元測試中。
在進行數據庫測試時能夠:
簡化單元測試數據庫連接的設置,
簡化利用DBUnit測試數據的插入,
簡化Hibernate session管理,
自動測試與數據庫相映射的Hibernate映射對象。
在利用Mock對象進行測試時能夠:
簡化EasyMock mock對象創建,
簡化mock對象注入,利用反射等式匹配EasyMock參數。
在與Spring集成時易於把spring管理的bean注入到單元測試中,支持在單元測試中使用一個用Spring配置的Hibernate SessionFactory。
- Equality assertion through reflection
- Possibility to ignore order of collections and Java default/null values
MOCK模塊(Mock module) - Makes mocking easy and maintainable
- Simple syntax for defining and asserting invoked behavior
- Gives you the best possible feedback so you can easily find out why a test is failing
- Argument matchers, partial mocking, stubbing behavior, dummy objects...
注入模塊(Inject module) - Easily inject test artifacts into classes and instances
- Inject values by type and name
- Inject into static fields, e.g. singletons, and automatically reset the old value after the test
IO模塊(IO module) - Support for performing IO in tests
- Creating temporary files and directories
- Loading the contents of files into objects
數據庫測試(Database testing) - Support for testing with databases and loading of DbUnit data sets
- Simplify test database connection setup
- Support for setting up a separate schema/database per developer
- Transactional testing
- Easy loading of data sets
- Multi-schema data sets
- Expected data set assertions
數據庫維護自動測試 (Automatic test database maintenance) - Use DbMaintain to automatically bring your unit test databases up to date before running your tests
- Automatic maintenance of databases with support for incremental, repeatable and post processing scripts
- Automatically disable constraints and set sequences to a minimum value
- Generating an XSD of the database structure for dataset xml files
Hibernate模塊(Hibernate module) - Support for Hibernate database testing
- Hibernate SessionFactory creation and session management
- Automatically test the mapping of JPA entities / hibernate mapped objects with the database
Spring模塊(Spring module) - Support for testing when your project uses Spring
- ApplicationContext configuration and easy injection of spring managed beans into a unit test
- Support for using a Spring-configured Hibernate SessionFactory in unit tests.
EasyMock模塊(EasyMock module) - Helps you set up tests that use EasyMock as a mocking framework
- Simplify EasyMock mock object creation
- EasyMock argument matching using reflection equality