Skip to content

Demonstrates a simple framework for writing unit tests for database code.

License

Notifications You must be signed in to change notification settings

akalnay/DbUnitTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DbUnitTest

This project demonstrates a simple framework for writing unit tests for database code. I am using the term "framework" in a very loose way here as the framework in question consists of a single abstract class (DatabaseTestsBase) that test classes should inherit from if the intent is to create unit tests for code that requires a database.

The abstract methods in DatabaseTestsBase are self-explanatory with their intent easily inferred from their names: OpenConnection(), CreateDatabaseTables(), and AddDataToDatabaseTables().

DatabaseTestsBase is DBMS agnostic, it doesn't care what the underlying DBMS is. This is accomplished via the GetDbProviderFactory() method which descendant classes must override. In practical terms however, the fact that good unit tests must be fast, repeatable, and isolated, implies that the DBMS should be an in-memory database. This allows for the database to be quickly created when needed and for it to be in a consistent state. The unit tests in this project rely on a SQLite database which has the option to run entirely in memory.

The origin of this project is my finding that the documentation for the Fill(Int32, Int32, DataTable[]) overload of the DbDataAdapter class was missing some details. I wanted to have a way to easily document the missing bits and writing unit tests is what made the most sense. I reported the issue to Microsoft: DbDataAdapter.Fill Method Documentation appears to be incomplete.

About

Demonstrates a simple framework for writing unit tests for database code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages