【问题标题】:Difficulty getting full list of tests cases in test set难以在测试集中获得完整的测试用例列表
【发布时间】:2014-05-09 14:55:16
【问题描述】:

我使用 C# 中的 Rally Rest API Ver 2.0.1.0 创建了一个应用程序,使我的测试工程师能够使用 CSV 文件以自动方式修改 Rally 测试数据。

我希望应用程序能够找到现有的测试集,获取该集中的测试用例列表,向该列表添加更多测试用例,然后使用新的测试用例列表更新测试集。

我的问题是,当我得到测试集中的测试用例列表时,即使测试集中有超过 20 个测试用例,Rally 也只返回 20 个测试用例。

为了得到测试集中的测试用例列表,这里是我的代码(我很抱歉没有所有的声明,但我想你明白了):

public ArrayList testSetList = new ArrayList(); 

Request requestTS = new Request("TestSet");

requestTS.Project = rallyProjectRef;

requestTS.ProjectScopeDown = false;

requestTS.ProjectScopeUp = false;

requestTS.Fetch = new List<string> { "Name", "ObjectID", "Iteration", "TestCases" };

requestTS.Query = new Query("Name", Query.Operator.Equals, testSetName).And(new Query("Iteration", Query.Operator.Equals, currentIterationRef));

try
{
    QueryResult findTSMatchQueryResult = m.myRestApi.Query(requestTS);
    string currentTestSetRef = "/TestSet/" + findTSMatchQueryResult.Results.First()["ObjectID"];

     string testCasesintheTestSEt = currentTestSetRef + "/TestCases";
     DynamicJsonObject item = m.myRestApi.GetByReference(testCasesintheTestSEt, "TestCase", "ObjectID");
     foreach (var testCaseObject in item["Results"])
     {
         testSetList.Add(testCaseObject);
     }

循环遍历GetByReference 方法的结果时,只返回了20 个测试用例对象。有没有办法让我使用这个 GetByReference 方法来扩展返回对象的数量?或者是否可以设置一个查询来获取测试集中测试用例对象的完整列表?

我使用上述方法是因为我注意到当使用 Update 方法“更新”测试集中的测试用例时,Rally 将清除所有现有数据,并将新的测试用例列表视为完整的测试用例集在测试集中。也许还有另一种方法可以在不清除现有测试用例的情况下将测试用例添加到现有测试集中?

目前,当尝试更新测试集中的测试用例时,我使用以下代码,如果testCaseList 不包含先前存在的测试用例,则从测试集中删除已经存在的测试用例。

DynamicJsonObject toUpdate = new DynamicJsonObject();
toUpdate["TestCases"] = testCasesList;
try
{
    OperationResult updateOperationResult = m.myRestApi.Update(currentTestSetRef, toUpdate);
    if (updateOperationResult.Success == true)
    {
        return "Added the test case to the test set. ";
    }
    else
    {
        return "Error.  An error occurred trying to update the test case list of the test set. ";
    }
}
catch (Exception)
{
    return "Error.  An exception occurred trying to update the test cases list of the test set. ";
}

任何帮助将不胜感激。

【问题讨论】:

    标签: c# rally


    【解决方案1】:

    对于任何请求,您都可以将请求限制设置为足够高的数字,例如:

    requestTS.Limit = 1000;
    

    有关请求成员的更多信息,请参阅文档here

    至于向测试集上的现有测试用例集合添加新的测试用例,您对对象模型的看法是正确的,即在 WS API 中,TestCase 上没有 TestSet 属性。这是一个完整的代码,它将一个测试用例添加到该测试集上现有的 23 个测试用例的集合中,并且在更新集合之前返回所有 23 个。

    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System.Text;
    using Rally.RestApi;
    using Rally.RestApi.Response;
    
    namespace addTCtoTS
    {
        class Program
        {
            static void Main(string[] args)
            {
                RallyRestApi restApi;
                restApi = new RallyRestApi("user@co.com", "secret", "https://rally1.rallydev.com", "v2.0");
    
                String projectRef = "/project/222"; 
                Request testSetRequest = new Request("TestSet");
                testSetRequest.Project = projectRef;
                testSetRequest.Fetch = new List<string>()
                    {
                        "Name",
                "FormattedID",
                        "TestCases"
                    };
    
                testSetRequest.Query = new Query("FormattedID", Query.Operator.Equals, "TS22");
                QueryResult queryTestSetResults = restApi.Query(testSetRequest);
                String tsRef = queryTestSetResults.Results.First()._ref;
                String tsName = queryTestSetResults.Results.First().Name;
                Console.WriteLine(tsName + " "  + tsRef);
                DynamicJsonObject testSet = restApi.GetByReference(tsRef, "FormattedID", "TestCases");
                String testCasesCollectionRef = testSet["TestCases"]._ref;
                Console.WriteLine(testCasesCollectionRef);
    
                ArrayList testCasesList = new ArrayList();
    
                foreach (var ts in queryTestSetResults.Results)
                {
                    Request tcRequest = new Request(ts["TestCases"]);
                    QueryResult queryTestCasesResult = restApi.Query(tcRequest);
                    foreach (var tc in queryTestCasesResult.Results)
                    {
                        var tName = tc["Name"];
                        var tFormattedID = tc["FormattedID"];
                        Console.WriteLine("Test Case: " + tName + " " + tFormattedID);
                        DynamicJsonObject aTC = new DynamicJsonObject();
                        aTC["_ref"] = tc["_ref"];
                        testCasesList.Add(aTC);  //add each test case in the collection to array 'testCasesList'
                    }
                }
    
         Console.WriteLine("count of elements in the array before adding a new tc:" + testCasesList.Count);
    
              DynamicJsonObject anotherTC = new DynamicJsonObject();
              anotherTC["_ref"] = "/testcase/123456789";             //any existing test to add to the collection
    
               testCasesList.Add(anotherTC);
    
               Console.WriteLine("count of elements in the array:" + testCasesList.Count);
               testSet["TestCases"] = testCasesList;
               OperationResult updateResult = restApi.Update(tsRef, testSet);
    
            }
        }
    }
    

    代码可在this github repo.获取

    【讨论】:

    • 我的 requestTS 是获取与我的查询匹配的 TestSet 引用的请求。发出此请求的结果不包含返回的测试集中的测试用例对象。然后我必须使用 GetByReference 方法来获取测试集中的测试用例的arrayList,但是这种方法最多只能返回一个数组列表中的 20 个测试用例对象。我不相信可以请求测试集名称 == "example" 的测试用例,因为测试用例对象没有测试集属性。
    • 我在上面的帖子中包含了一个代码示例。在示例中,我将第 24 个测试用例添加到现有的 23 个集合中。您是正确的,在 WS API 中,TestCase 上没有 TestSet 属性。
    【解决方案2】:

    换句话说,您的问题的答案是“否” - 无法让 GetByReference 返回测试集中的所有测试用例 - 它一次返回 20 个。为了得到测试集中>20个测试用例的数组,你必须使用上面的查询方法,遍历结果,并将每个结果放入一个数组中。

    ArrayList TestCaseList = restApi.GetByReference(TestSet["TestCases"]["_ref"])["Results"];
    

    只会返回最多 20 个结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-20
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多