2

如何使用 JUnit 测试 Java EE Web 服务端点方法?

我在Eclipse中使用SpringMyBatis框架和标准Maven目录结构。我知道我可以通过为它创建一个 JUnit 测试用例来简单地测试每个方法。但是,我想知道如何使用@WebService、@WebMethod、@WebResult 标签进行测试。

@WebService(endpointInterface = "com.ws.BrowserService", name = "BrowserService", targetNamespace = "http://abc.def.com")
public interface BrowserService {

    /**
     * Runs the provided SQL query and returns the result.
     * @param queryText is the SQL query text.
     * @return The query result is returned in the form of List<Object>.
     */
    @WebMethod
    @WebResult(name = "Object")
    public List<Object> runQuery(
            @WebParam(name = "QueryText") String queryText);

}

编辑

执行

@WebService(targetNamespace = "http://abc.def.com", portName = "BrowserPort", serviceName = "BrowserService")
public class BrowserServiceImpl implements BrowserService {

    @Autowired
    private QueryMapper queryMapper;

    public List<Object> runQuery(String queryText) {
        List<Object> queryResult= new ArrayList<Object>();
        queryResult = queryMapper.runQuery(queryText);
        return queryResult;
    }
}
4

1 回答 1

0

事实证明,我实际上正在寻找的是集成测试

于 2014-06-25T15:47:19.340 回答