I've just encountered an error in my app that probably could have been caught with some integration tests, so I think its high time I wrote some!
My question relates to the setup of these tests, and at what layer of the code you run the tests against.
Setup
Considering I should have lots of integration tests, I don't want to be creating and dropping a test database for every test, this would be epically slow (even if its an SqlLite in-memory one). My thoughts are:
- Have a test db which sits next to my dev db
- Before testing, run some reset script which will set up my schema correctly and insert any necessary data (not test case specific)
- Simply use this test db as if its the real db.
However, it seems very wasteful that I have to run my Fluent NHib configuration in every [Setup]. Is this just tough? What are my options here?
My session is currently wrapped in a UoW pattern, with creation and destruction performed on begin_request and end_request (MVC web application) respectively. Should I modify this to play well with the tests to solve this problem?
Testing
When it comes to actually writing some tests, how should I do it?
Should I test from the highest level possible (my MVC controller actions) or from the lowest (repositories).
If I test at the lowest I'll have to manually hard code all the data. This will make my test brittle to changes in the code, and also not representative of what will really happen in the code at runtime. If I test at the highest I have to run all my IoCC setup so that dependencies get injected and the whole thing functions (again, repeating this in every [SetUp]?)
Meh! I'm lost, someone point me in the right direction!
Thanks