5

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?


.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Does this answer your question? [Karate Spring Integration](https://stackoverflow.com/questions/53642974/karate-spring-integration) – Peter Thomas Mar 31 '21 at 02:42

1 Answers1

3

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.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    Thank you, Peter. I am currently consulting a team whose productivity is compromised by the need to continually deploy services to WebSphere. Your solution here would be huge. My client has a Testing Tools organization that is currently evaluating several tools, including Karate and REST Assured. I have informed the organization of your efforts toward providing this feature. I have opened [an issue on Karate in GitHub](https://github.com/intuit/karate/issues/100). – Daniel Steinberg Jul 07 '17 at 15:42
  • @DanielSteinberg acknowledged ! I'm going to take a look at the options. – Peter Thomas Jul 07 '17 at 16:19
  • @DanielSteinberg - I've updated the GitHub issue with a commit that has a full example (Jersey). Even if your env is not Jersey, you should be able to create a custom mock using the approach demonstrated. I'd like to get feedback from you and your team before releasing this into the next Karate version. – Peter Thomas Jul 08 '17 at 06:46