How I can extend the capability of the DatabaseUnitTest?
I want to log the execution result of my UnitTests in my database.
I created a class that will insert data in my database
class LogUnitTest
{
public static void LogPassedTest(string res)
{
using (var conn = new SqlConnection("myConnection"))
using (var command = new SqlCommand("InsertTestResult", conn))
{
conn.Open();
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@Output", "Passed"));
command.ExecuteNonQuery();
}
}
}
I edit my unit test
public void Training_uspInsertHorseHealthHKJC()
{
try
{
SqlDatabaseTestActions testActions = this.Training_uspInsertOrderData;
// 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...");
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);
LogUnitTest.LogPassedTest("Passed");
}
catch(Exception ex )
{
LogUnitTest.LogPassedTest(ex.ToString());
}
}
But my unitest always log the result as passed even though I know that this should return an error.
Aucun commentaire:
Enregistrer un commentaire