java - Rally toolKit for Java 如何创建 TestCaseResult 并将其附加到 TestCase

标签 java rally testcase

一般代码,其中 testCaseJsonObject:

JsonObject result = new JsonObject();
result.addProperty("Verdict", "True");
result.addProperty("TestCase", Ref.getRelativeRef(testCase.get("_ref").getAsString()));

CreateRequest createRequest = new CreateRequest("TestCaseResult", result);
CreateResponse createResponse = restApi.create(createRequest);

我想我的两个主要问题是:

  1. 我是否正确创建了 testCaseResult?(testCase 属性是对 testCase 的引用)
  2. 我需要将 testCaseResult 附加到我的 testCase 中吗? (testCase.addProperty("结果", "testCaseResults 引用")

最佳答案

谢谢凯尔!作为示例,这里有一个快速片段,说明了查询测试用例,然后向其中添加新的测试用例结果:

    // Create and configure a new instance of RallyRestApi
    RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com"), 
            "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3c6c0d6c1f3d0dcdec3d2ddca9dd0dcde" rel="noreferrer noopener nofollow">[email protected]</a>", "password");
    restApi.setWsapiVersion("1.34");
    restApi.setApplicationName("RestExample_AddTagsToTestCase");        

    //Query User
    QueryRequest userRequest = new QueryRequest("User");
    userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName"));
    userRequest.setQueryFilter(new QueryFilter("UserName", "=", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87f2f4e2f5c7e4e8eaf7e6e9fea9e4e8ea" rel="noreferrer noopener nofollow">[email protected]</a>"));
    QueryResponse userQueryResponse = restApi.query(userRequest);
    JsonArray userQueryResults = userQueryResponse.getResults();
    JsonElement userQueryElement = userQueryResults.get(0);
    JsonObject userQueryObject = userQueryElement.getAsJsonObject();
    String userRef = userQueryObject.get("_ref").toString();

    // Query for Test Case to which we want to add results
    QueryRequest testCaseRequest = new QueryRequest("TestCase");
    testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
    testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC4"));
    QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
    JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
    String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").toString();

    try {

        //Add a Test Case Result                
        System.out.println("Creating Test Case Result...");
        JsonObject newTestCaseResult = new JsonObject();
        newTestCaseResult.addProperty("Verdict", "Pass");
        newTestCaseResult.addProperty("Date", "2012-06-12T18:00:00.000Z");
        newTestCaseResult.addProperty("Notes", "Automated Selenium Test Runs");
        newTestCaseResult.addProperty("Build", "2012.05.31.0020101");
        newTestCaseResult.addProperty("Tester", userRef);
        newTestCaseResult.addProperty("TestCase", testCaseRef);

        CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
        CreateResponse createResponse = restApi.create(createRequest);            

        if (createResponse.wasSuccessful()) {

            System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));          

            //Read Test Case
            String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
            System.out.println(String.format("\nReading Test Case Result %s...", ref));
            GetRequest getRequest = new GetRequest(ref);
            getRequest.setFetch(new Fetch("Date", "Verdict"));
            GetResponse getResponse = restApi.get(getRequest);
            JsonObject obj = getResponse.getObject();
            System.out.println(String.format("Read Test Case Result. Date = %s, Verdict = %s",
                    obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));                 
        } else {
            String[] createErrors;
            createErrors = createResponse.getErrors();
            System.out.println("Error occurred creating Test Case: ");
            for (int i=0; i<createErrors.length;i++) {
                System.out.println(createErrors[i]);
            }
        }

    } finally {
        //Release all resources
        restApi.close();
    }

关于java - Rally toolKit for Java 如何创建 TestCaseResult 并将其附加到 TestCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10987076/

相关文章:

java - 为什么在交互中的同步集合中再次同步?

java - 类型的生命周期

java - 使用集合与优先级队列实现的二叉堆的渐近复杂性

javascript - 如何让测试用例显示在 Rally 纸板上?

android - 在 TestCase 中启动第二个 Activity (这不是被测 Activity )

java - 我如何制作这个图形用户界面?

javascript - CA Rally - 并发冲突 : [Object has been modified since being read for update in this context] Error

java - Rally Rest Api-Android 应用程序-即使在导入所需的 jars 后也找不到类

java - GetRequest集会限制pageSize

javascript - 如何在正则表达式中使用模板文字?