Xml 如何为Junit测试用例编写xPath
我有以下XML字符串, 如何编写XPath以获取值“rest/accounts/123” 但是线路 MockMvcResultMatchers.xpath(“/account/atom:link/href()”)字符串( Matchers.containssString(“/rest/accounts/123”)) 是投掷错误 根据建议,我将代码更改为Xml 如何为Junit测试用例编写xPath,xml,spring-mvc,xpath,junit,mockito,Xml,Spring Mvc,Xpath,Junit,Mockito,我有以下XML字符串, 如何编写XPath以获取值“rest/accounts/123” 但是线路 MockMvcResultMatchers.xpath(“/account/atom:link/href()”)字符串( Matchers.containssString(“/rest/accounts/123”)) 是投掷错误 根据建议,我将代码更改为 mockMvc.perform( MockMvcRequestBuilders.get("/rest/acco
mockMvc.perform(
MockMvcRequestBuilders.get("/rest/accounts/123").contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_XML))
.andDo(print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(
MockMvcResultMatchers.xpath("/account/atom:link/@href,").string(
Matchers.containsString("/rest/accounts/123")))
.andExpect(MockMvcResultMatchers.xpath("/account/name/text()").string(Matchers.equalTo("satya")));
// .andExpect(MockMvcResultMatchers.jsonPath("$.links[*].href").exists());
}
Junit测试用例给出错误
com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
前缀必须解析为名称空间:atom
您可以使用
后的子字符串功能:
substring-after(//atom:link/@href, "http://localhost/")
您可以使用后的子字符串功能:
substring-after(//atom:link/@href, "http://localhost/")
添加上述更改后,仍然会出现Junit测试用例错误,如中所示problem@Satya当前位置我不熟悉您使用的库。我回答了原来的问题。也许您需要注册atom
名称空间?添加上述更改后,仍然会出现Junit测试用例错误,如中所示problem@Satya当前位置我不熟悉您使用的库。我回答了原来的问题。也许您需要注册atom
名称空间?
substring-after(//atom:link/@href, "http://localhost/")