Showing posts with label static imports. Show all posts
Showing posts with label static imports. Show all posts

Friday, July 31, 2015

The method print() is undefined for the type Controller


The method print() is undefined for the type Controller

Problem :


I came across this common exception when i was using mocks for unit testing spring application.

Exception I Encountered Was :


###################################################################################################################

The method print() is undefined for the type Controller

###################################################################################################################

Solution :


When unit testing your spring application with mocks you need to make sure that you are using the neccessary static imports in your code.
See below for the list of static imports to use.
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; 

Once i had the static import in place it resolved the exception. Hope this helps resolve your exception, Happy Coding.

Similar Exception :


- How to test a spring controller method by using MockMvc?
- My test helper methods get() status() are undefined
- the method post(string) is undefined for controller test
- Integration testing of spring MVC applicaitons


Tuesday, June 30, 2015

The method post(string) is undefined for controller test


The method post(string) is undefined for controller test

Problem :


I came across this common exception when i was using mocks for unit testing spring application.

Exception I Encountered Was :


################################################################################################### ################

the method post(string) is undefined for controller test

################################################################################################### ################

Solution :


When unit testing your spring application with mocks you need to make sure that you are using the necessary static imports in your code.
See below for the list of static imports to use.
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

Once i had the static imports in place it resolved the exception. Hope this helps resolve your exception, Happy Coding.

Similar Exception :


- How to test a spring controller method by using MockMvc?
- My test helper methods get() status() are undefined
- the method post(string) is undefined for controller test
- Integration testing of spring MVC applicaitons
- the method print() is undefined for the type Controller