Wednesday, May 18, 2011

TFS 2010 API - Get Results of a Test Run

3 comments:

  1. We request you suggestion for the problem statement mentioned below.

    Problem Statement:
    In Coded UI for running the automated tests from MTM Currently we are hard coding DataSource test case ID As shown below.

    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.TestCase", "httpTFSURL", "2200", DataAccessMethod.Sequential), TestMethod]
    public void UserLogin()
    {

    if (TestContext != null)
    {
    }
    }

    What I am trying is if I can get the Test case Id which is currently executing either from Current Test Context or From TFS tables.

    I have gone through the TFS tables and found that the following tables are being used for storing the data related to Test Runs.

    • dbo.tbl_TestRun
    • dbo.tbl_TestMessageLogEntry
    • dbo.tbl_TestMessageLog

    With following Query I am able to get the Test Case ID but I am struggling to execute this Query through TFS API. I request your help there. We request your suggestion on the approach we are following. Is it correct or can we follow an alternate approach?

    select
    case WHEN(ISNUMERIC(substring(message,CHARINDEX('[', message)+1,4))=1)THEN
    substring(message,CHARINDEX('[', message)+1,4) END
    from tbl_TestMessageLogEntry a,tbl_testrun b
    where State=2 and a.TestMessageLogId=b.TestMessageLogId
    and ISNUMERIC(substring(message,CHARINDEX('[', message)+1,4))<>0

    Thanks
    --Naren

    ReplyDelete
  2. You can use TFS API to get the testcase id from the combination of testcase name, test class name and assembly name. Take a look at http://blogs.msdn.com/b/visualstudioalm/archive/2011/12/30/how-to-get-the-test-case-associated-with-the-unit-test.aspx

    ReplyDelete
  3. Hi Anuj,
    Thanks for sharing the tool but will this also work against the TFS/MTM 2013?

    Many Thanks
    Saurabh

    ReplyDelete