Is there a mechanism for integration testing JAX-R

2019-06-27 09:11发布

问题:

I have successfully built no-deployment-needed integration test frameworks for Spring MVC REST services using Mock MVC. I am struggling to do the same with JAX-RS services.

REST Assured looks promising, but it seems to require deployment. The test suite can start up a CXF server, but can it wire it up with a servlet container?

It seems that the unique value provided by Mock MVC is in its mock servlet container. Does any other technology provide this.

The JAX-RS testing page of the CXF documentation provides a pattern for injecting a mock HttpServletRequest into a CXF invoker. Which got me thinking ...

Spring MVC's mock servlet elements (MockHttpServletRequest, etc.) come from the spring-test module, is independent of Mock MVC. Would we be able to inject these objects into a CXF invoker? Or will this be a rabbit hole?

Has anyone come up with a solution to this problem?


.

回答1:

Daniel - I'm the developer of Karate and something I've been experimenting with is to use a combination of Mockito and the Spring mocks for the HTTPServletRe**** to call a servlet directly and avoid having to boot an app-server.

Since Karate has this swappable abstraction of an http-client, I was thinking of adding this option in the near future.

Just sharing in case it helps you with ideas, or if you want to compare notes. Feel free to open a thread on GitHub.

Update: I made very good progress on this - please look at this thread for a working example.