locked
SQLProject Code Coverage in VS 2012 RRS feed

  • Question

  • 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);
            }

    Friday, August 30, 2013 5:40 PM

Answers

  • Hello,

    Please try to right click your test method in test explorer window and check if Analyze Code Coverage for Selected Tests is available. If yes, please try to select it to collect code coverage for this SQL Server unit test.

    Best regards,


    Amanda Zhu <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 2, 2013 9:33 AM
  • Hi,

    If you means that you want to get the coded coverage for your database project, I doubt that it will have some limitations like the following thread.

    http://social.msdn.microsoft.com/Forums/en-US/8c5999ea-0584-402d-8035-2fbed19d34ce/sql-code-coverage-in-vs2010

    Best Regards,


    Jack Zhai[MSFT]
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, September 17, 2013 2:05 AM

All replies

  • Hello,

    Please try to right click your test method in test explorer window and check if Analyze Code Coverage for Selected Tests is available. If yes, please try to select it to collect code coverage for this SQL Server unit test.

    Best regards,


    Amanda Zhu <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 2, 2013 9:33 AM
  • Hi,

    If you means that you want to get the coded coverage for your database project, I doubt that it will have some limitations like the following thread.

    http://social.msdn.microsoft.com/Forums/en-US/8c5999ea-0584-402d-8035-2fbed19d34ce/sql-code-coverage-in-vs2010

    Best Regards,


    Jack Zhai[MSFT]
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, September 17, 2013 2:05 AM