我试图从Java运行SoapUI测试 . 我在ReadyApi中准备了一个项目,它正在使用Rest服务和两个步骤 . 在第一步(groovy脚本)中,我设置了测试用例属性(从JSON加载值),第二步是Rest请求 . 如果我从ReadyApi提交请求,一切进展顺利,我得到了正确的回复 .

但是,如果我尝试从Java执行此测试用例,我会得到以下响应:

08:23:03,028 DEBUG [HttpClientSupport $ SoapUIHttpClient]尝试1执行请求08:23:03,029 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]发送请求:POST /进程/操作/执行HTTP / 1.1 08:23:04,391 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]接收响应:HTTP / 1.1 401 Unauthorized 08:23:04,396 DEBUG [HttpClientSupport $ SoapUIHttpClient]连接可以无限期保持活动08:23:04,396 DEBUG [HttpClientSupport $ SoapUIHttpClient]目标请求认证08:23:04,398 DEBUG [HttpClientSupport $ SoapUIHttpClient]授权质询处理08:23:04,399 DEBUG [HttpClientSupport $ SoapUIHttpClient]认证范围:BASIC @endpointAddress:443 08:23:04,399 INFO [HttpAuthenticationRequestFilter $ UPDCredentialsProvider] endpointAddress:443要求使用领域'null'进行认证08:23: 04,400 DEBUG [HttpClientSupport $ SoapUIHttpClient]发现凭据08:23:04,403 DEBUG [HttpClientSuppor t $ SoapUIHttpClient]尝试2执行请求08:23:04,403 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]发送请求:POST /进程/操作/执行HTTP / 1.1 08:23:09,061 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]接收响应:HTTP / 1.1 400错误请求08:23:09,062 DEBUG [HttpClientSupport $ SoapUIHttpClient]连接可以无限期保持活动08:23:41,067 DEBUG [SoapUIMultiThreadedHttpConnectionManager $ SoapUIDefaultClientConnection]连接已关闭

我的Java代码:

List<TestSuite> testSuiteList = new ArrayList<TestSuite>();
    List<TestCase> testCaseList = new ArrayList<TestCase>();

    SoapUI.setSoapUICore(new StandaloneSoapUICore(true));

    TestRunner testRunner = null;
    try {
        WsdlProject project = new WsdlProject("C:/Users/User/soapui - projects/rest-soapui-project.xml");
        testSuiteList = project.getTestSuiteList();
        Map<String,TestProperty> propertyMap;

        for (int i = 0; i < testSuiteList.size(); i++) {
            testSuiteName = testSuiteList.get(i).getName();

            System.out.println(testSuiteName);
            testCaseList = testSuiteList.get(i).getTestCaseList();
        }
        for (int i = 0; i < testCaseList.size(); i++) {
           testCaseName = testCaseList.get(i).getName();
            propertyMap = testCaseList.get(i).getProperties();
            for (Map.Entry<String, TestProperty> entry :
                    propertyMap.entrySet()) {
                String key = entry.getKey();
                TestProperty value = entry.getValue();
                System.out.println(key);
                System.out.println(entry.getValue().getValue());

            }
        }
        testRunner = project.getTestSuiteByName(testSuiteName).getTestCaseByName(testCaseName).run( new PropertiesMap(),false);

    } catch (XmlException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SoapUIException e) {
        e.printStackTrace();
    }