java - 使用 Rest API 更新 Rally 测试用例结果

标签 java web-services rest testing rally

在 Rally 中有一个用于测试用例结果更新的 Rest Webservice URI。 https://rally1.rallydev.com/slm/webservice/v2.0/testcaseresult/create

有人能告诉我这个的有效负载应该是什么吗? 可以给我一个工作示例。

我已经搜索了 2 天,但找不到我想要的信息。 最接近的是:Rally add test case results in bulk using web services API

但是这也没有帮助..

最佳答案

您的有效载荷是多少? 您收到的错误是什么? 您引用的帖子对于以前版本的 WS API 是正确的。 v2.0 不支持 XML,只支持 JSON。

至少,必须在有效负载中设置以下字段

"{"TestCaseResult":{"Build":"1","Date":"2014-09-04T19:56:05.000Z","TestCase":"/testcase/12358743669","Verdict":"Pass"}}"

这是一个完整的 curl 示例。在 Windows 上转义双引号的位置:

curl --header "zsessionid:_abc123" -H "Content-Type: application/json" -d"{\"TestCaseResult\":{\"Build\":\"1.0\",\"TestCase\":\"/testcase/12358743669\",\"Date\":\"2014-09-04T19:56:05.000Z\",\"Verdict\":\"Pass\"}}" https://rally1.rallydev.com/slm/webservice/v2.0/TestCaseResult/create

由于您在帖子中使用了 java 标签,这里是一个基于 Rally Java toolkit 的示例.

public class addTCRtoTC {

    public static void main(String[] args) throws URISyntaxException, IOException {
        String host = "https://rally1.rallydev.com";
            String username = "user@co.com";
            String password = "secret";
            String wsapiVersion = "v2.0";
            String projectRef = "/project/2222";      
            String workspaceRef = "/workspace/11111"; 
            String applicationName = "RestExample_AddTCR";

        RallyRestApi restApi = new RallyRestApi(
                new URI(host),
                username,
                password);
        restApi.setWsapiVersion(wsapiVersion);
        restApi.setApplicationName(applicationName);   

        //Read User
        QueryRequest userRequest = new QueryRequest("User");
        userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName", "SubscriptionAdmin"));
        userRequest.setQueryFilter(new QueryFilter("UserName", "=", "nick@wsapi.com"));
        QueryResponse userQueryResponse = restApi.query(userRequest);
        JsonArray userQueryResults = userQueryResponse.getResults();
        JsonElement userQueryElement = userQueryResults.get(0);
        JsonObject userQueryObject = userQueryElement.getAsJsonObject();
        String userRef = userQueryObject.get("_ref").getAsString();  
        System.out.println(userRef);

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

        try {
            for (int i=0; i<2; i++) {

                //Add a Test Case Result    
                System.out.println(testCaseRef);
                System.out.println("Creating Test Case Result...");
                JsonObject newTestCaseResult = new JsonObject();
                newTestCaseResult.addProperty("Verdict", "Pass");
                newTestCaseResult.addProperty("Date", "2014-03-07T18:00:00.000Z");
                newTestCaseResult.addProperty("Notes", "Some Scheduled Test");
                newTestCaseResult.addProperty("Build", "2.0");
                newTestCaseResult.addProperty("Tester", userRef);
                newTestCaseResult.addProperty("TestCase", testCaseRef);
                newTestCaseResult.addProperty("Workspace", workspaceRef);

                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("my 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 Result: ");
                    for (int j=0; i<createErrors.length;j++) {
                        System.out.println(createErrors[j]);
                    }
                }
            }


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

    } 

}

关于java - 使用 Rest API 更新 Rally 测试用例结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26979217/

相关文章:

node.js - Loopback - 如何获取用户的ID并插入到相关模型中? (有很多)

java - 为什么字符串在许多编程语言中是不可变的?

java - 运行 Riak 的示例 TasteOfRiak.java 时连接意外关闭

java - JNI 访问对象的实例变量

c# - 可以与 WCF 交互的 Java Web 服务工具包

java - JSR 跨域验证

java - 当Java Web服务部署在运行同一应用服务器的不同操作系统上时,同一消息的不同数字签名

python - 在 Django Rest Framework 中获取特定对象

java - Azure REST API 使用 java 获取存储 Blob 大小详细信息

java - 如何重命名文件名而不改变其类型?