we are doing database business logic unit testing using MSTest.We created several projects based on database schema.Each project has two test classes(one for UDSPs, another for UDFs).
Currently we are invoking data generation method in the class initialize method of every class.
We know that MS test does parallel execution of unit tests which means multiple classes may invoke data generation method parallely.For example if i have 5 distinct projects, data is generated 10( 5*2) times in the target database.
My questions are
1.How SQL server handles this situation?
2.How to ensure data generation only once irrespective of number of projects and number of test classes in each project.
3.What is the correct approach for this kind of scenario?
Thanks & Regards
Monday, May 28, 2012 11:03 AM
- Moved by Jack Zhai - MSFTMicrosoft contingent staff, Moderator Tuesday, May 29, 2012 7:41 AM The database unit test issue. (From:Visual Studio Unit Testing)
Thank you for posting in the MSDN forum.
I moved this issue to the correct forum. I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
Jack Zhai [MSFT]
MSDN Community Support | Feedback to us
Tuesday, May 29, 2012 7:45 AMModerator
This is really outside the scope of the tool and depends on your process. If you are doing this kind of parallelization you need to execute the data generation ahead of time. For instance, you could use the data generation MSBuild task or write a console app that does the execution ahead of any test execution.
These questions require a more in-depth level of support. I suggest you visit the following link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
Thanks,Tuesday, June 19, 2012 2:25 PM
Well, it really depends on what you are achieving here.
For instance, the scope of applying TDD on a Database is not to improve scalability during the test execution. I understand that your tests keep running for a long time but that's how is supposed to be. Parallelizing unit tests over the same resource is wrong and against the principles of TDD because you loose the isolation of the expected results.
The right approach is to isolate the tests especially because they shouldn't run against the same SQL instance in parallel because SQL can't handle parallelisms over a Table and you should know that. When you CRUD a table, SQL apply a lock on it which may incur in providing the wrong data to your unit tests.
If I have to execute parallels tests over a SQL instance and the scope of the tests is not to tests the performances of the database, I would move those tests into separate instances of SQL, that's the only real parallel solution you can apply to your problem.
If you want to initialize the database using some mock data for the entire set of tests (which goes against TDD principles ...) you need to work with the MSTest attributes and create a Setup() method where you will initialize the data for the entire set of tests.
MCAD - MCSD MCTS Sharepoint 2007 MCTS SQL Server 2005 MCTS TFS 2010 IASA Architect blog: http://blog.raffaeu.com "If my answer is useful remember to mark it as useful".Thursday, July 05, 2012 5:28 PM