I'm going to write unit tests for any new web application.

My preferred technique is to check from the live database structure instead of an in-memory database.

I realize will be able to wrap my unit test database calls inside transactions that aren't committed.

Things I think is really a better approach would be to copy the live database before initialising the tests, and permit the transactions to invest in the exam database. When the exams are run within the correct order this can let me produce a complete test story from signing up the very first account, through their various interactions, ending by having an account closure. i.e. a real life lifecycle. I'm convinced this ought to be a great approach, but getting never put this into practice yet I'm wondering if people had attempted an identical approach and exactly what the feedback is before I proceed. Thanks ahead of time.

Unit tests shouldn't rely on their order, and cannot rely on the condition of what's being examined. They ought to setup all necessary condition.

What you've referred to might be a helpful test, but it is not some unit tests.

I understand I will be that guy using this method, but allows establish our terms here before continuing to move forward. Skip this part should you only worry about the solution.

A Unit Test should test exactly that, just one unit. It shouldn't depend on exterior dependencies for example databases, web services, or file systems. Rather, individuals dependencies ought to be mocked to ensure that the condition of every individual test could be precisely controlled.

A Unit Test ought to be atomic, consistent and repeatable. As John highlights, the exam should have the ability to be run alone, or perhaps in a suite using the identical behavior each time.

An Integration Test should test the interaction between your various models that compose the body. Thus, they ought to never aim to stub or mock any dependencies. These tests ought to be as near to testing what's going to be used to production as possible accomplished.

Allow me to be the first one to tell you just how even though it is very common for Integration Tests to become determined by setup and destroy, tread gently within this arena.

Sure it appears like an excellent idea to start with, as well as the same reason why procedural code usually eventually ends up like a nightmare to keep, procedural exams are a whole lot worse. Being that they are so tightly combined towards the implementation particulars from the underlying code, you'll finish up needing to change massive teams of tests should you ever change individuals particulars.

Within the best situation scenario you'll discard large teams of tests and begin again. Within the worst situations you'll hesitate to refactor the body because you won't want to break your results... and therefore take advantage of you of the extremely advantage they are meant to bring.

The best way forward I can provide you with would be to start reading through on Acceptance Testing, and Behavior Driven Development.

Many People who are able to help:

Gojko Adzic, Bob Martin

Some Tools that will help:

FitNesse, SpecFlow, Cucumber

Please! Please! Please! read and study from individuals men, and individuals towns. They'll steer you within the right direction and assist you to avoid long-term issues with automated testing.