Is there a mechanism for integration testing JAX-RS services without deploying (a la MockMVC)?
Asked Answered
I

1

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?


.

Inveigle answered 28/6, 2017 at 21:14 Comment(1)
Does this answer your question? Karate Spring IntegrationRoommate
R
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.

Roommate answered 5/7, 2017 at 3:4 Comment(3)
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.Inveigle
@DanielSteinberg acknowledged ! I'm going to take a look at the options.Roommate
@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.Roommate

© 2022 - 2024 — McMap. All rights reserved.