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

  • SEARCH
  • Home
  • 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 7593457
In Process

The Archive Base Latest Questions

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

I initially just had a Java Servlet that I needed to unit test. I

  • 0

I initially just had a Java Servlet that I needed to unit test. I wanted to make sure it would handle requests correctly, so I used Spring’s MockHttpServletRequest in a jUnit test and that method worked great. Very simple unit test.

Now, I want to extend the test and I want to do a series of database transactions and mock http servlet requests to simulate users using the system over a period of time.

I guess I could cram all of this into a single unit test but that doesn’t seem like the right thing to do since it would violate the spirit of a unit test.

So what is the proper way to test a series of events in a particular order like this?

Here’s a stripped down version of what I have so far:

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations={"testContext.xml"}) 
public class servletTest {

//Injected request
@Resource(name="mockTestServletRequest")
MockHttpServletRequest request;

@Test
public void mockRequest() {
    //perform a mock servlet request
}

So do I simulate a timeline of events by just adding more methods annotated with @Test above and below the one I have already ? Am I guaranteed that these methods will be executed in the order listed?

  • 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. Editorial Team
    Editorial Team
    2026-05-30T21:10:27+00:00Added an answer on May 30, 2026 at 9:10 pm

    That will be an integration test. Take a look at spring’s testing framework. This means you will start your spring context, and have everything running. You can either use an in-memory database, or a standalone one.

    When everything is started, you can inject an instance of a controller of yours and trigger a request, then another one. By default each method is in a transaction, which gets rolled back when the method completes, so don’t worry about polluting the database.

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

Sidebar

Related Questions

Initially I had a method in our DL that would take in the object
I have a UIViewController class MyClass that initially had no XIB, and was initialized
In the test project for my android app I initially had a series of
Ok, initially this was just a joke we had with a friend of mine,
I wanted to add a table and a foreign key to that table. Initially
Initially this demo application I'm working on had just one page with a simple
So, I have an autocomplete dropdown with a list of townships. Initially I just
I just found the MVC was initially proposed in 88 [ here is the
Initially I wanted a checkmark where the text is placed on the left of
I've had an intermittent problem that I thought was due to un-cleared floats. What

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.