• Save
Java Unit Testing with Unitils
Upcoming SlideShare
Loading in...5
×
 

Java Unit Testing with Unitils

on

  • 6,535 views

Presentation from JEEConf conference (Kiev, May 2011) about unit testing in Java with Unitils library.

Presentation from JEEConf conference (Kiev, May 2011) about unit testing in Java with Unitils library.

Statistics

Views

Total Views
6,535
Views on SlideShare
5,716
Embed Views
819

Actions

Likes
6
Downloads
0
Comments
0

7 Embeds 819

http://jeeconf.com 812
url_unknown 2
http://twitter.com 1
http://xpinjection.com 1
http://www.techgig.com 1
http://webcache.googleusercontent.com 1
https://twitter.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Java Unit Testing with Unitils Java Unit Testing with Unitils Presentation Transcript

  • Java Unit Testing with Unitils
    Mikalai Alimenkou
    http://xpinjection.com
    21.05.2011
  • Background
    Java Technical Lead/Scrum Master at Zoral Labs
    6+ years in software development
    4+ years of working by Agile methodologies
    Expert in Agile engineering practices
    Founder and coachat XP Injection (http://xpinjection.com)
    Organizer of Selenium Camp and JEEConf conferences
  • General Idea
    TestNG
  • Unitils History
    Spring test integration
    Multi db support
    Various improvements
    Unitils 3.0
    DbMaintain 2.2
    Testing guidelines
    from brainstorm
    Separate modules
    Unitils 2.0
    Unitils 1.0
    DbMaintain 2.0
    DbMaintain separated
    from Unitils
    Unitils RC1
  • Unitils Facts
    Open source
    Integrates with JUnit and TestNG
    Modular and flexible architecture
    Lots of useful utilities
  • Modular Architecture
    Existing modules
    DatabaseModule
    DbUnitModule
    HibernateModule
    MockModule
    EasyMockModule
    InjectModule
    SpringModule
    Create new or change implementation
    Configure only needed modules
  • Flexible Configuration
    Everything is configurable
    3 levels of overridden properties
  • Database Testing
    Main problems
    Mocking or real data?
    JDBC, Hibernate, JPA, …
    Testing approaches
    Create database, clean database
    Local transactions
  • Unitils Solution
    Database maintainer
    Small test datasets with DbUnit
    @Transactional support
    Separate schema per developer
    Custom DataSource for more control
  • Database Maintenance
    Keep database schema in VCS
    Great versioning technique with incremental updates
    Ability to disable constraints
  • Database Maintenance
    Supports large number of databases
    Prepares sequences and identity columns
    Many options for database and data maintenance
    Generate XSD or DTD for DbUnit datasets
  • DbMaintain Project
    http://www.dbmaintain.org
    Separated from Unitils
    Can be used to automate deployment and upgrade procedure
    Version 2.3 in May 2011
  • DbMaintain Scripts Structure
    Incremental database updates
    Committed files are unchangeable
    Strict sequence
    Supports repeatable scripts, postprocessing
  • DbMaintain Scripts Structure
    Rename of scripts and folders is supported
    Multi-database and patches support
    Script information is stored in special table
  • DbMaintain Execution
    Ant
    <updateDatabasescriptLocations="${database.archive}">
    <database driverClassName="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:mem:mydb" userName="admin" password="pwd" schemaNames="PUBLIC" />
    </updateDatabase>
    Command line
    /path/to/dbmaintain/bin/dbmaintain.sh update path/to/scriptFolderOrArchive
    Java code
    URL configurationUrl = new File("dbmaintain.properties").toURI().toURL();
    MainFactorymainFactory = new MainFactory(configurationUrl);
    DbMaintainerdbMaintainer = createDbMaintainer();
    dbMaintainer.updateDatabase(false);
  • DbMaintain Commands
    createScriptArchive
    updateDatabase
    markErrorScriptPerformed
    markErrorScriptReverted
    markDatabaseAsUpToDate
    checkScriptUpdates
    clearDatabase
    cleanDatabase
    disableConstraints
    updateSequences
  • DbUnit Integration
    Small test datasets
    Only needed fields present
    XSD or DTD for XML datasets validation and autocompletion
  • DbUnit Integration
    Granular datasets on class or test level
    Flexible datasets naming policy
    Test and expected datasets
    Multiple datasets support
  • EasyMock Integration
    TestedObject concept
    Easy mocks creation with annotations
    Completely configurable mocks
    Extended set of parameter conditions
    Injection of mocks
  • Own Mocking Library
  • Own Mocking Library
    Can be used in parallel with EasyMock
    Mocking style like in Mockito
    Dummy objects
    Partial mocks
  • Spring Integration
    Context loading with caching
    Different types of Spring bean injection
    Ability to override beans by loading multiple contexts
  • Hibernate Integration
    Special test for mapping consistency
    Easy to create and inject SessionFactory
  • JPA Integration
    Supports Hibernate, Toplink, OpenJPA
    JpaEntityManagerFactory creates EntityManager for each test
    JPA utilities for injection and mapping validation
  • Assertion Utilities
    Reflection based
    Flexible comparison
    Ignore types of numbers and collections
    Ignore order in collections
    Ignore properties
    Able to compare only some properties
  • Assertion Utilities
    Supports object hierarchy
    Great differences reporting
    Lenient by default
  • Unitils Failures
    • First record in DbUnit dataset should have all columns used further
    • Conditions must be set for all parameters in method when using EasyMock
    • EasyMock error reports are hard to understand
    Many bugs in bug tracker
  • Any questions?