If you want to ensure the correctness of the business layer test, then we have to test the database. But at the moment I have not thought in memory to carry on the database test, only then carries on the integration test. So here's a look at the data layer test.
Because within the database we have no control we can only pass the black box test, give the value and then return the desired effect we want to determine whether it is successful. But in the test we have to ensure the uniqueness, metaphor in the test add when we add a piece of data then the database may produce a dirty data, if run once a day so the consequences are also terrible, but some people say that the region to add and delete together test, I think it is unreasonable, Because then you have a test both add and delete undesirable. Besides, if it's a change, what do you do? So you need to take a rollback mechanism when testing.
Rolling back data modifications using TransactionScope
Let's look at an example
First we define a TransactionScope
Private TransactionScope _scope;
And then initialize it in Setup.
[SetUp] Public void SetUp () { thisnew TransactionScope (transactionscopeoption.required); }
And then we can test to see the code below
[Test] publicvoid create_createsuccessful_returnstrue () { var userInfo = createuserinfo (); var New Userdal (); bool result = userdal.create (userInfo); Assert.istrue (result); }
Finally, we release this thing in the teardown.
[TearDown] Public void TearDown () { this. _scope. Dispose (); }
Ok so we have finished testing the data layer. Let's look at the results of the test
But there are some references to SOA that we just need to make sure we have the right configuration.
Source: http://www.cnblogs.com/LipeiNet/p/5062464.html
Unit Test database--using things to roll back tests