I'm creating my first SQL Server Unit Test in Visual Studio 2013. I have a script that runs successfully in a SQL Server Management Studio window. And I have a script that resets the database state, which also successfully runs. (I have that set up as my PreTest script.) My unit test takes about 2 minutes to run. (It's generating a lot of data behind the scenes.) But the SQL Server Unit Test appears to be configured to timeout after 30 seconds. I've been trying to find out how to change the timeout setting, but I can't seem to find it. (Please note that I'm not referring to the connection timeout, but the query execution timeout.) I'd like to run this test with a timeout setting of 3 minutes.
Thanks, in advance.
Figures, I spent an hour searching before posting the question, then I find the answer 10 minutes later. Here is the code for my test, with the line for the commandtimeout in it:
[TestMethod()]
public void CreateScenario_FromProject_Q123314_FromVersion_AA()
{
SqlDatabaseTestActions testActions = this.SqlTest1Data;
// Execute the pre-test script
//
System.Diagnostics.Trace.WriteLineIf((testActions.PretestAction != null), "Executing pre-test script...");
SqlExecutionResult[] pretestResults = TestService.Execute(this.PrivilegedContext, this.PrivilegedContext, testActions.PretestAction);
// Execute the test script
//
System.Diagnostics.Trace.WriteLineIf((testActions.TestAction != null), "Executing test script...");
this.ExecutionContext.CommandTimeout = 180; // HERE IS THE COMMANDTIMEOUT
SqlExecutionResult[] testResults = TestService.Execute(this.ExecutionContext, this.PrivilegedContext, testActions.TestAction);
// Execute the post-test script
//
System.Diagnostics.Trace.WriteLineIf((testActions.PosttestAction != null), "Executing post-test script...");
SqlExecutionResult[] posttestResults = TestService.Execute(this.PrivilegedContext, this.PrivilegedContext, testActions.PosttestAction);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With