I am trying to use the Spring modular MVC module to unit test my controllers. I added:
@Before
public void beforeTest() {
MockitoAnnotations.initMocks(this);
standaloneSetup(new CarController());
}
which works great. However, I created a controller board that has a method annotated with @ExceptionHandler. I want to check that it works during unit testing. I saw that I can build an object MockMvcand pass it to standaloneSetup(..):
MockMvcBuilders.standaloneSetup(
new CarController()).setHandlerExceptionResolvers(...).build();
However, when I do this, a test that checks the operation of the exception handler passes, but all other tests that access the answer using jsonpath cannot execute this error:
java.lang.IllegalStateException: Expected response body to be verified as JSON,
HTML or XML but content-type 'null' is not supported out of the box.
Try registering a custom parser using:
RestAssured.registerParser("null", <parser type>);
Content was:
How to fix it? What's wrong?
The bottom line is that I want unit test my rest api. How to do this if I added an exception handler?
source
share