distributedlife

passionate about everything

Copying tests between HP Service Test Projects adding tests is still too much work Published by Ryan Boucher @ 11:55 pm

Yesterday I showed some code for bulk adding new projects in HP Service Test. That wasn’t enough for me. Often we have a bunch of tests that need to be executed against each operation; security tests are good example. As such we want to copy and paste the tests and be done with it… but if the target project already exists you have to copy each action one at a time. Not a pleasant waste of time.

So the extension to yesterdays post is to change your UI so the user can specify a source project and then a target project. Write a function to parse the action names. The rest of your code is basically the same.

I made changes to my “is action name valid loop”. You could theoretically drop a bunch of checks that are no longer possible. I added one check to drop each test that already existed in the target.


//Get list of tests in 'from' project
List<String> AllFromTests = GetTestNamesAsString (Direction.From);

//Get list of tests already in 'to' project
List<String> ExistingToTests = GetTestNamesAsString (Direction.To);

List<string> TestsToAdd = new List<string> ();

foreach (string test in AllFromTests)
{
    string trimmed = test.Trim ();

    //skip empty strings
    if (String.IsNullOrEmpty (trimmed))
    {
        continue;
    }    

    //skip lines that are too long (shouldn't be possible)
    if (trimmed.Length > 63)
    {
    continue;
    }

    //replace all spaces with underscores (should have already occured)
    trimmed = trimmed.Replace (' ', '_');

    //skip invalid characters (shouldn't be possible)
    if (!Regex.IsMatch (trimmed, @"^[a-zA-Z0-9_]+$"))
    {
    continue;
    }

    //starts with a number (shouldn't be possible)
    if (Regex.IsMatch (trimmed, @"^[0-9]"))
    {
    continue;
    }

    //skip tests that exist in the target
    if (ExistingToTests.Exists (delegate(string a) {return (a.Equals (trimmed));}))
    {
        continue;
    }

    TestsToAdd.Add (trimmed);
}
My Mug Ryan Boucher is a Software Inquisitor and is passionate about it. You can find a whole raft of articles and anecdotes about software testing and other topics he gets excited about.
Tags , , , , , , ,