Testing database content with DBUnit. My experience.
-
Upload
serhii-kartashov -
Category
Technology
-
view
248 -
download
0
Transcript of Testing database content with DBUnit. My experience.
Can you test database layer more smart than usual?
Serhii KartashovDecember 2012SoftServe
Agenda
What’s a problem?
How we want to resolve that?
Are you professional?
Agenda
What’s a problem?
How we want to resolve that?
Are you professional?
Problem
Task:
please remove old and didn’t marked data from production!
The problem is this:
you have a SQL database, some stored procedures, and a layer of code sitting between your application and the database. How can you put tests in place to make sure your code really is reading and writing the right data from the database?
What’s the best practice? You need [multiple] databases!
Aster
SQL Oracle
MySQL
Aster
Oracle
MySQL
Aster
Oracle
MySQL
devQA (local) prodQA production
How I wanted to do that? First step: initialization test data.
con.
Prepare the data
object file network
SQL commit
First step: create the Test and call API.
How I wanted to do that? First step: initialization test data.
con
.
Actual Data
DB
SQL
Expected Data
Compare
Agenda
What’s a problem?
How we want to resolve that?
Are you professional?
Ideal schema
DB DBDB
Initialize call API Actual dataExpected
data
Compare
Step 1 Step 2 Step 3
File
File
Agenda
What’s a problem?
How we want to resolve that?
Are you professional?
DBUnit Framework
DBUnit Core Components
• IDatabaseConnection - interface representing a DbUnitconnection to a DB
• IDataSet - interface representing a collection of tables• DatabaseOperation - abstract class representing an operation
performed on the database before and after each test. Operations:
• NONE• UPDATE• INSERT• REFRESH• DELETE• DELETE_ALL• TRUNCATE_TABLE• CLEAN_INSERT (DELETE_ALL and INSERT)
IDatabaseConnection
IDataSet: database
DataBase
client_id item_id item_name
analytics_comments
client_id item_id item_name
200 01 name - #1
200 02 name - #2
200 03 name - #3
IDataSet: XML file Initialized
Expected
Database Operation: setUp()
Simple JUnit test
A bit more
Supported RDBMS
• OracleDatabase• MsSQL• MySQL• IbmDB2• IbmInformix• H2• HypersonicSQL• PostgreSQL• SybaseSQL• InterBase• OpenBase8• SapDB/MaxDB• Derby• FrontBase
Where is Aster database???
NOTE: 1. latest version of DBUnit framework doesn’t support Oracle Schemas…2. and very inert community…
Thank you!
Questions?