Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit tests vs integration tests with Spring
    primarykey
    data
    text
    <p>I'm working on a Spring MVC project, and I have unit tests for all of the various components in the source tree.</p> <p>For example, if I have a controller <code>HomeController</code>, which needs to have a <code>LoginService</code> injected into it, then in my unit test <code>HomeControllerTest</code> I simply instantiate the object as normal (outside of Spring) and inject the property:</p> <pre><code>protected void setUp() throws Exception { super.setUp(); //... controller = new HomeController(); controller.setLoginService( new SimpleLoginService() ); //... } </code></pre> <p>This works great for testing each component as an isolated unit - except now that I have a few dozen classes in the project, after writing a class and writing a successful unit test for it, I keep forgetting to update my Spring MVC context file that does the actual wiring-up in the deployed application. I find out that I forgot to update the context file when I deploy the project to Tomcat and find a bunch of NullPointers from non-wired-up beans.</p> <p>So, here are my questions:</p> <ol> <li><p>This is my first Spring project - is it normal to create unit tests for the individual beans, as I have done, and then create a second suite of tests (integration tests) to test that everything works as expected with the actual application context? Is there an established best practice for this?</p></li> <li><p>In addition, how do you separate the unit tests from the integration tests? I have all of the source code in <code>src</code>, the unit tests in <code>test</code> - should there be a 2nd test folder (such as <code>test-integration</code>) for integration test cases?</p></li> </ol> <p>Since this is my first Spring project, I'm curious how others usually go about doing this sort of thing - and rather than re-invent the wheel I rather ask the rest of the community.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload