【问题标题】:Rally toolKit for Java how do i create and then attach a TestCaseResult to a TestCaseRally toolKit for Java 如何创建 TestCaseResult 并将其附加到 TestCase
【发布时间】:2012-06-11 20:27:06
【问题描述】:

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("Results", "testCaseResults reference")

【问题讨论】:

    标签: java rally testcase


    【解决方案1】:

    谢谢凯尔!举例来说,这里有一个快速的 sn-p,它说明了查询一个测试用例,然后向它添加一个新的测试用例结果:

        // Create and configure a new instance of RallyRestApi
        RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com"), 
                "user@company.com", "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", "=", "user@company.com"));
        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();
        }
    

    【讨论】:

      【解决方案2】:

      指定与新测试用例结果关联的测试用例的 ref 是执行此操作的正确方法。一旦创建操作成功,再次查询测试用例应该在其结果集合中包含新创建的测试用例结果。

      【讨论】:

        猜你喜欢
        • 2012-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-17
        相关资源
        最近更新 更多