JUnit and SoapUI Integration example.
groovy:
========================
def xpathAssertion = testRunner.testCase.testSteps["name_of_your_step"].addAssertion("XPath Match")
xpathAssertion.setPath("your_xpath")
xpathAssertion.setExpectedContent("expected_result")
xpathAssertion.setName("your_required_name_xpath")
def containsAssertion = testRunner.testCase.testSteps["name_of_your_step"].addAssertion("Contains")
containsAssertion.setToken("your_expected_string")
containsAssertion.setName("your_required_name_contains")
JUnit:
=========================
WsdlProject project = new WsdlProject(PropertiesFactory.getString("SOAPUI_PROJECT_FILE_PATH"));
List<TestSuite> testSuiteList = project.getTestSuiteList();
for(TestSuite testSuite : testSuiteList){
List<TestCase> testCaseList = testSuite.getTestCaseList();
for(TestCase testCase : testCaseList){
String testCaseName = testCase.getName();
String testCaseProperties = PropertiesFactory.getString("SoapUIProject", testCaseName);
testCase.setPropertyValue("assertions", testCaseProperties);
//testCase.setPropertyValue("assertions", "[\"NewOperation\", \"My_xpath_match1\", \"XPath Match\", \"//*[local-name()='ReversedString']\", \"DCBA\"]");
TestRunner testCaseRunner = testCase.run(new StringToObjectMap(), false);
assertEquals( TestRunner.Status.FINISHED, testCaseRunner.getStatus( ));
}
}
Properties:
=========================
assertion2=NewOperation, My_xpath_match1, XPath Match, //*[local-name()='ReversedString' and namespace-uri()==${rev}]
groovy:
========================
def xpathAssertion = testRunner.testCase.testSteps["name_of_your_step"].addAssertion("XPath Match")
xpathAssertion.setPath("your_xpath")
xpathAssertion.setExpectedContent("expected_result")
xpathAssertion.setName("your_required_name_xpath")
def containsAssertion = testRunner.testCase.testSteps["name_of_your_step"].addAssertion("Contains")
containsAssertion.setToken("your_expected_string")
containsAssertion.setName("your_required_name_contains")
JUnit:
=========================
WsdlProject project = new WsdlProject(PropertiesFactory.getString("SOAPUI_PROJECT_FILE_PATH"));
List<TestSuite> testSuiteList = project.getTestSuiteList();
for(TestSuite testSuite : testSuiteList){
List<TestCase> testCaseList = testSuite.getTestCaseList();
for(TestCase testCase : testCaseList){
String testCaseName = testCase.getName();
String testCaseProperties = PropertiesFactory.getString("SoapUIProject", testCaseName);
testCase.setPropertyValue("assertions", testCaseProperties);
//testCase.setPropertyValue("assertions", "[\"NewOperation\", \"My_xpath_match1\", \"XPath Match\", \"//*[local-name()='ReversedString']\", \"DCBA\"]");
TestRunner testCaseRunner = testCase.run(new StringToObjectMap(), false);
assertEquals( TestRunner.Status.FINISHED, testCaseRunner.getStatus( ));
}
}
Properties:
=========================
assertion2=NewOperation, My_xpath_match1, XPath Match, //*[local-name()='ReversedString' and namespace-uri()==${rev}]
本文介绍了一个JUnit与SoapUI集成使用的示例代码,演示了如何通过Groovy脚本在JUnit测试中运行SoapUI测试用例,并进行断言验证。具体包括XPath匹配和字符串包含断言的设置。
63

被折叠的 条评论
为什么被折叠?



