c# - 难以获取测试集中测试用例的完整列表

标签 c# rally

我使用 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. ";
}

任何帮助将不胜感激。

最佳答案

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

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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6b3b5a3b486a5a9e8a5a9ab" rel="noreferrer noopener nofollow">[email protected]</a>", "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.中找到

enter image description here

关于c# - 难以获取测试集中测试用例的完整列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23567774/

相关文章:

c# - 仅来自基类的函数

java - 使用 Rally Rest for Java 将测试用例步骤添加到测试用例

c# - 如何在 Entity Framework Core 中调用带有多个表联接的存储过程?

c# - 手动调用事件处理程序

security - RallyRestApi 使用 HTTP GET 或 POST 方法吗?

java - 如何在 Java 的 Rally Rest 工具包中获取整个 TestFolders 树?

javascript - Rally - 按里程碑名称过滤史诗

javascript - Rally App SDK 2.0 : Ext. 元素方法 "unselectable"未标准化

c# - LINQ 比较属性值不相等的两个列表

c# - GridView导出Excel时如何隐藏到列?