Unit Test in Maven requires access to the src/main/webapp Directory

后端 未结 4 1255
小鲜肉
小鲜肉 2021-01-04 09:32

I am trying to unit test a webapp that I am developing in Maven/Eclipse. It is a Spring MVC webapp, and I need some unit tests to test my model controller.

To do thi

4条回答
  •  暖寄归人
    2021-01-04 10:07

    In general, you should be using mocks (e.g., EasyMock or jMock) to handle unit testing for your controller; a unit test should test a component in isolation from the rest of the system. In Spring 3, you can define your Controllers as a POJO with annotations and then simply test the Controllers without any interaction from Spring at all.

    If you wish to do more integration-level testing, then you can place common parts of config files in src/main/resources so they become accessible in the classpath. Then use a test specific configuration in src/test/resources for your test. That file can either import those files along with anything you need, or you can annotate your test case with @ContextConfiguration to specify the multiple files that are needed to assemble the context.

    For a concrete example, see this blog post on integration testing Spring MVC. The Testing chapter of the Spring manual also has a decent overview of integration testing in Spring.

提交回复
热议问题