Troubleshooting Database Unit Testing Issues
You might encounter the issues in this topic when you perform unit tests on a database:
You can configure a unit test to automatically deploy the database and generate data. If you lack sufficient permissions to generate data to the target database, you might receive an error that indicates only that you lack permissions to connect to the database.
To work around this issue, run the data generation plan manually. If you lack sufficient permissions to generate data, this approach will give you a more detailed error message that helps you to correct the problem.
If you modify the App.Config file in the test project, you must rebuild the test project before those changes will take effect. These changes include those that you make to App.Config by using the Project Configuration dialog box. If you do not rebuild the test project, the changes are not applied when you run the unit tests.
If you deploy a database when you perform unit tests, the database is created by using the connection string information that is specified in your unit test configuration. The connection information that is specified in the database project build properties is not used for this task, so you can run different unit tests against different instances of the same database.
If your database unit tests are failing because of a time-out, you can increase the time-out period by updating the app.config file in your database project. The time-out on the connection string specifies how long to wait when the unit test connects to the server. The command time-out specifies how long to wait when the unit test executes the Transact-SQL script.
To work around this issue, specify a larger value for the CommandTimeout attribute on the appropriate Context element in the app.config file for your test project. For example, to specify a command time-out of 120 seconds for the PrivilegedContext element, update the app.config as follows:
<DatabaseUnitTesting> <DatabaseDeployment DatabaseProjectFileName="test.dbproj" Configuration="Debug" /> <DataGeneration DataGenerationFileName="test.dgen" ClearDatabase="true" /> <ExecutionContext Provider="System.Data.SqlClient" ConnectionString="another connection string" /> <PrivilegedContext Provider="System.Data.SqlClient" ConnectionString="test" CommandTimeout="120" /> </DatabaseUnitTesting>