Search code examples
javaunit-testingspring

Spring: I wish to create a junit test for a web application - WebApplicationContext needed


I am writing a junit test in order to (surprisingly) test a part of my app as a standalone.

Thing is I execute the following line in a constructor being invoked in the unit test:

WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();

How would I go about to set up a web context when running a simple unit test?

Thanks


Solution

    • In unit tests, test with mocks.
    • In integration tests you may actually want to start an embedded servlet container. Here's a approach.