I have recently discovered Spring project for MVC testing: spring-test-mvc. It’s a great tool, and I plan to use it more in the future.
However I have noticed a problem with it on my Jenkins CI. The problem is that while MVC integration tests are passing locally, and even on Jenkins CI job, the problem occurs in the Jenkins’ Sonar plugin execution. In this case all asserts done with “.andExpect()” method I tried fail. Yes, they pass if Sonar plugin is not used.
For example
this.mockMvc.perform(get("/someController/some.action").param("someParam", "someValue"))
.andExpect(status().isOk())
.andExpect(content().type(MediaType.APPLICATION_JSON))
.andExpect(request().sessionAttribute("someAttribute", notNullValue()));
In the above test content type and session attribute assertions are failing.
Any ideas? Thanks in advance.
The problem is solved by kind people from spring-mvc. More details can be found on the provided link. In short, in my case Sonar uses Cobertura for coverage testing.
The problem is solved by adding
proxy-target-class="true"to<tx:annotation-driven>element