Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Can you test database layer more 
smart than usual? 
Serhii Kartashov 
December 2012 
SoftServe
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! 
devQA (local) prodQA production 
MySQL 
SQL Oracle 
Aster 
MySQL 
Oracle 
Aster 
MySQL 
Oracle 
Aster
How I wanted to do that? First step: 
initialization test data. 
object file network 
con. 
Prepare the 
data 
SQL commit
First step: create the Test and call API.
How I wanted to do that? First step: 
initialization test data. 
SQL 
con. 
Actual Data 
DB 
Expected Data 
Compare
Agenda 
What’s a problem? 
How we want to resolve that? 
Are you professional?
Ideal schema 
Step 1 Step 2 Step 3 
Initialize call API Actual data 
DB DB DB 
Expected 
data 
Compare 
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 DbUnit 
connection 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 
analytics_comments 
client_id item_id item_name 
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?

More Related Content

Testing database content with DBUnit. My experience.

  • 1. Can you test database layer more smart than usual? Serhii Kartashov December 2012 SoftServe
  • 2. Agenda What’s a problem? How we want to resolve that? Are you professional?
  • 3. Agenda What’s a problem? How we want to resolve that? Are you professional?
  • 4. 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?
  • 5. What’s the best practice? You need [multiple] databases! devQA (local) prodQA production MySQL SQL Oracle Aster MySQL Oracle Aster MySQL Oracle Aster
  • 6. How I wanted to do that? First step: initialization test data. object file network con. Prepare the data SQL commit
  • 7. First step: create the Test and call API.
  • 8. How I wanted to do that? First step: initialization test data. SQL con. Actual Data DB Expected Data Compare
  • 9. Agenda What’s a problem? How we want to resolve that? Are you professional?
  • 10. Ideal schema Step 1 Step 2 Step 3 Initialize call API Actual data DB DB DB Expected data Compare File File
  • 11. Agenda What’s a problem? How we want to resolve that? Are you professional?
  • 13. DBUnit Core Components • IDatabaseConnection - interface representing a DbUnit connection 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)
  • 15. IDataSet: database DataBase analytics_comments client_id item_id item_name client_id item_id item_name 200 01 name - #1 200 02 name - #2 200 03 name - #3
  • 16. IDataSet: XML file Initialized Expected
  • 20. 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…