locked
Testing Extensibility!! RRS feed

  • Question

  • Hi,

    Is there an object model for VSTT , i haven't explored much on extensibility on this front..

    Another thing I wanted to do was to capture the status of Test Case (Work Item) run during exec time.. Either triggered from Camano or VS itself, say figure out when it starts, and when it ends and its final outcome (manual or automated)? How can i achieve this?

    Need pointers, Thanks in advance..

    Regards
    Gopal
    Monday, December 22, 2008 5:59 AM

Answers

  •  The API allows you to take over control of running and managing tests, the code below is from a prototype so the final is slightly different but you get the idea, there is a simple and slightly more advanced example


    SIMPLE EXAMPLE
    ============
    TestCollection tc = new TestCollection();
    tc.Load("testcontainer.dll");

    TestRunner runner = new TestRunner();
    TestRunResult runResult = runner.Run(tc);

    Console.WriteLine("Test run result: {0}", runResult.Outcome));
    foreach (TestResult result in runResult.TestResults)
    {
     Console.WriteLine("[{0}]\t{1}\t{2}",result.Outcome,
                result.TestName,
                result.ErrorMessage);
    }


    MORE ADVANCED EXAMPLE
    ===================

          string[] testContainers = new string[2] { "testcontainer.dll", "mytests.dll" };

          TestCollection tc = new TestCollection();
          tc.Load(testContainers);

          TestSettings ts = new TestSettings("default.testsettings");

          var filteredTests = (from subsetTests in tc
                               where subsetTests.Information.FullContainerName == "mytests.dll"
                               || subsetTests.Priority == 1
                               select subsetTests);

          TestRunner tr = new TestRunner();

          tr.RunCompleted += new EventHandler<TestRunCompletedEventArgs>(tr_RunCompleted);
          tr.TestCompleted += new EventHandler<TestCompletedEventArgs>(tr_TestCompleted);

          tr.RunAsync((TestCollection)filteredTests, ts);


    http://blogs.msdn.com/euanga
    • Marked as answer by emptyseas Tuesday, January 20, 2009 5:00 PM
    Wednesday, January 7, 2009 9:26 PM

All replies

  • Hi Gopal - there is an OM for TCM which lets you create/edit test cases programmatically. You should be able to browse these classes in the class view window

    Re the test execution extensibility APIs that you are asking for, I am not very sure if this is a part of the released CTP bits or not. Will check back on that one.

    - Anu

    http://blogs.msdn.com/anutthara
    Monday, December 22, 2008 8:59 AM
  • Hey Anu,

    Thanks for the quick response, I did explore the former part of my query, it's cool..
    Please let me know about the latter , that would be great..also is this available in 2008 version???, for eg. if i run a UT, can i know its state as run or failed or completed..


    ~Gopal
    Tuesday, December 23, 2008 4:32 AM
  • The API is not in the current CTP but will be in the next public release, ti si not available in the 2008 version. You will be able to recover the result state for a UT when you run it.

    -Euan
    http://blogs.msdn.com/euanga
    Tuesday, December 30, 2008 4:38 AM
  • Oh ok...Thanks for the info Euan...

    If i am not wrong, you mean to say that only for a UT i can check the state of it whether its passed or failed, as and when i run it. thats during runtime or its just a query to the Data store which yields the result of the last run??


    Friday, January 2, 2009 6:29 AM
  •  The API allows you to take over control of running and managing tests, the code below is from a prototype so the final is slightly different but you get the idea, there is a simple and slightly more advanced example


    SIMPLE EXAMPLE
    ============
    TestCollection tc = new TestCollection();
    tc.Load("testcontainer.dll");

    TestRunner runner = new TestRunner();
    TestRunResult runResult = runner.Run(tc);

    Console.WriteLine("Test run result: {0}", runResult.Outcome));
    foreach (TestResult result in runResult.TestResults)
    {
     Console.WriteLine("[{0}]\t{1}\t{2}",result.Outcome,
                result.TestName,
                result.ErrorMessage);
    }


    MORE ADVANCED EXAMPLE
    ===================

          string[] testContainers = new string[2] { "testcontainer.dll", "mytests.dll" };

          TestCollection tc = new TestCollection();
          tc.Load(testContainers);

          TestSettings ts = new TestSettings("default.testsettings");

          var filteredTests = (from subsetTests in tc
                               where subsetTests.Information.FullContainerName == "mytests.dll"
                               || subsetTests.Priority == 1
                               select subsetTests);

          TestRunner tr = new TestRunner();

          tr.RunCompleted += new EventHandler<TestRunCompletedEventArgs>(tr_RunCompleted);
          tr.TestCompleted += new EventHandler<TestCompletedEventArgs>(tr_TestCompleted);

          tr.RunAsync((TestCollection)filteredTests, ts);


    http://blogs.msdn.com/euanga
    • Marked as answer by emptyseas Tuesday, January 20, 2009 5:00 PM
    Wednesday, January 7, 2009 9:26 PM
  • Thanks Euan, looking forward to this :)
    Tuesday, January 20, 2009 5:00 PM