Skip to content

Integration Testing Guidelines

Wade Baglin edited this page Apr 14, 2019 · 7 revisions

Integration tests are testing PetaPoco end-to-db (plus other minor situations). Our primary purpose for having integration tests is so that we can ensure the consumer that PetaPoco works against the supported DB of their choosing. Additionally, it helps us know that with each release we haven't introduced bugs within the test coverage. Ultimately, this leads to a more stable product and means happier developers!

Sometimes choosing between integration testing and unit tests isn't so easily seen, so these are the PetaPoco guidelines for deciding.

Integration testing if:

  1. You are testing a component to ensure it is working when combined with all other components (PetaPoco as a whole)
  2. Or, you require a real DB to ensure the component works correctly
  3. Or, the bug you're reporting is for a specific DB instance
  4. Or, you can't easily mock/stub and running the test in a live environment is easier

Regarding point 4. Yes, we know that mocks/stubs/abstractions/xyz could achieve the same. However, as PetaPoco is about simplicity and we prefer to keep it simple, clean and easily understood.

Adding tests

Generic tests must be easily be run against all supported DBs. Only DB specific tests should be limited to a particular DB type. Please refer to existing integration tests to see how we achieve this goal.

When adding a model (AKA entity/POCO) ensure corresponding DDL scripts have been modified to include the new model.

Solution layout

Test file layout

File name:

The name of the test must describe what is being tested. For example, SqliteDeleteTests tests Sqlite deleting operations.

Test name:

The test name must be in the format of {this method/operation}_{this/theses conditions}_{expected result}. For example, Delete_GivenPoco_ShouldDeletePoco and Update_GivenPocoUpdateSql_ShouldUpdateThePoco. The only exception here is confirming an exception is thrown. For example Delete_GivenDbGoesAway_Throws.

Questions

  • Can I use another test framework, like Nunit? No!
  • Can I implement tests in my own way? No!
  • I only use SQLCe, can I skip the other DBs? No!
  • Should I keep it consistent? Yes!
  • Do I have to write unit/integration tests? Yes!