1

In Visual Studio 2012 I have a .SQLProj to control our SPs and functions. We have a Unit Testing project with test methods as illustrated below. The Unit Tests are wired into our CI server successfully. My question is, how can we go about generating unit test code coverage metrics for this project?

[TestMethod()]
    public void dbo_spGetSPFooterSectionTest()
    {
        SqlDatabaseTestActions testActions = this.dbo_spGetSPFooterSectionTestData;
        // 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);
    }
  • What are you trying to get coverage of, the SQL? – Shaun Wilde Aug 31 '13 at 11:01
  • The goal is to ensure that, at least at a high level, each SP has at least 1 unit test. If there is a solution that covers branching and everything then great, otherwise the high level is fine. – user2734248 Oct 14 '13 at 18:28
  • I've used [tSQLt](http://tsqlt.org/) for unit testing before but nothing I've seen will allow you to do "code coverage" on SQL. If you developed using TDD techniques along with tSQLt I would't worry too much about coverage if your testing is good. – Shaun Wilde Oct 15 '13 at 19:32

0 Answers0