none
How to run subset of tests using HCK APIs in powershell script? RRS feed

  • Question

  • Hi,

    I am writing a script to create  a project and run HCK tests on a device. Instead of running all the tests, I want to run a subset of tests - basically read tests from a text file and schedule them to run. How would I do this using HCK APIs?

    I know from TargetFamilies HCK Sample that the following code would schedule all the tests-

    $Project.GetTests() | foreach {
        "test {0} is {1}" -f  $_.Name, $_.ScheduleOptions.ToString()
        Write-Host "running test {0} " -f $_.Name
        $_.QueueTest();        
        }

    How can I force my project to run only suppose 5 tests read from a text file?

    Thanks,

    Disha

    Tuesday, December 11, 2012 1:32 AM

Answers

  • Hi Disha,

    One thing you can do is,

    1) Read all the test names in an array from the text file, say array is $testNames

    2) Once you have selected all the targets in a project, you can simply retrieve all the tests from that project as:

    $tests=$project.GetTests()

    3) And then you can do this:

    foreach($test in $tests)

    {

    if($testNames -contains $test.Name )

    {

    $test.QueueTest()

    }

    }

    Also, TargetFamilies are optional, you can directly add targets to the productInstances...this is how I do :)
    Regards,

    Nilesh

    Tuesday, December 11, 2012 6:42 AM

All replies

  • Hi Disha,

    One thing you can do is,

    1) Read all the test names in an array from the text file, say array is $testNames

    2) Once you have selected all the targets in a project, you can simply retrieve all the tests from that project as:

    $tests=$project.GetTests()

    3) And then you can do this:

    foreach($test in $tests)

    {

    if($testNames -contains $test.Name )

    {

    $test.QueueTest()

    }

    }

    Also, TargetFamilies are optional, you can directly add targets to the productInstances...this is how I do :)
    Regards,

    Nilesh

    Tuesday, December 11, 2012 6:42 AM
  • Thanks for your respnse. I will try it out
    Friday, December 14, 2012 1:44 AM
  • That worked. I had another question regarding Applying Filters from my script:

    Q1. How can we confirm that the following code has actually applied filters and exited successfully. Can we find out from the logs somehow?

    # apply filter to the project. Reload the project in HCK Studio after running the script.
    $result = $filterEngine.Filter($project)

    The reason I ask is, I printed $project.GetAppliedFilters().Count after doing the above, and it prints 0 as the count. 

    Q2. Is it compulsory to reload the project in Studio after applying filters from a script? I want to just have a script which creates project, runs tests, applies filters and create a package.

    Tuesday, December 18, 2012 12:37 AM
  • That worked. I had another question regarding Applying Filters from my script:

    Q1. How can we confirm that the following code has actually applied filters and exited successfully. Can we find out from the logs somehow?

    # apply filter to the project. Reload the project in HCK Studio after running the script.
    $result = $filterEngine.Filter($project)

    The reason I ask is, I printed $project.GetAppliedFilters().Count after doing the above, and it prints 0 as the count. 

    Q2. Is it compulsory to reload the project in Studio after applying filters from a script? I want to just have a script which creates project, runs tests, applies filters and create a package.

    Tuesday, December 18, 2012 12:37 AM
  • Hi Disha,

    A1. I have answered it on the thread which you have started for the same questions. :)

    A2. No, it is not compulsory to reload the project in studio after applying filters, i would suggest do not use studio when using scripts. Both scripts and studio GUI, work separately on, what MSFT calls it as "HCK database", studio is just the GUI to show whats in the database currently. API is much more nicer then the Studio. Even I'm working on HCK automation for my company, I like to run tests using my code, more than using the studio. :)

    Thanks,

    Nilesh

    Tuesday, December 18, 2012 6:50 AM