问题
I am using temporary database for my unit tests that are created and deleted with each test but have been very careful to ensure that it shares the same setup as my 'real' database (enlist=false;multipleactiveresultsets=true;etc) but have been constantly running into MSDTC escalation issues wherever TransactionScope is being used.
After switching TransactionScope for Transaction I have solved the MSDTC escalation issue and run straight into a new problem - the transaction works perfectly as I use the application in the web browser, but it fails in unit testing with the following error:
SqlConnection does not support parallel transactions.
Without posting tons of code, has anyone else run into similar problems where the test environment and dev environment appear to work differently? Is there any general reason why a parallel transaction would work in dev and not in unit test mode?
If I cannot simulate exactly what is happening with my tests then what is the point in testing at all?
回答1:
One big difference that I failed to account for was where I may be using RenderAction
in a view, and therefore calling more controller actions than the test would, which may explain MSDTC/Transaction
issue.
来源:https://stackoverflow.com/questions/9636533/mvc3-differences-between-test-environment-and-dev-application