Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 80463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:18:24+00:00 2026-05-10T21:18:24+00:00

I’m working on a Spring MVC project, and I have unit tests for all

  • 0

I’m working on a Spring MVC project, and I have unit tests for all of the various components in the source tree.

For example, if I have a controller HomeController, which needs to have a LoginService injected into it, then in my unit test HomeControllerTest I simply instantiate the object as normal (outside of Spring) and inject the property:

protected void setUp() throws Exception {     super.setUp();     //...     controller = new HomeController();     controller.setLoginService( new SimpleLoginService() );     //... } 

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.

So, here are my questions:

  1. 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?

  2. In addition, how do you separate the unit tests from the integration tests? I have all of the source code in src, the unit tests in test – should there be a 2nd test folder (such as test-integration) for integration test cases?

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:18:24+00:00Added an answer on May 10, 2026 at 9:18 pm

    I can’t speak to being a best practice, but here’s what I’ve done in the past.

    Unit tests:

    • Create unit tests for non-trivial beans (ie, most of your Spring related beans)
    • Use Mocks for injected services where practical (ie, most if not all the time).
    • Use a standard naming convention for these tests in the project test directory. Using Test or TestCase as a prefix or suffix to the classname seems to be widely practiced.

    Integration Tests:

    • Create an AbstractIntegrationTestCase that sets up a Spring WebApplicationContext for use in intetgration test clases.
    • Use a naming convention for integration tests in the test directory. I’ve used IntTest or IntegrationTest as a prefix or suffix for these tests.

    Set up three Ant test targets:

    1. test-all (or whatever you want to name it): Run Unit and Integration Tests
    2. test: Run Unit tests (just because test seems to be the most common usage for unit testing
    3. test-integration: run the integration tests.

    As noted, you can use the naming conventions that make sense for your project.

    As to separating unit from integration tests into a separate directory, I don’t think it matters as long as the developers and their tools can find and execute them easily.

    As an example, the last Java project I worked on with Spring used exactly what is described above, with integration tests and unit tests living in the same test directory. Grails projects, on the other hand, explicitly separate unit and integration test directories under a general test directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Apparently, a phantom <tbody> element appears in the output. The… May 11, 2026 at 2:40 pm
  • added an answer We use a macro to specifically indicate when something is… May 11, 2026 at 2:40 pm
  • added an answer http://www.w3.org/WAI/WCAG20/from10/diff.php and http://www.w3.org/WAI/WCAG20/from10/comparison/ May 11, 2026 at 2:40 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.