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 6952889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:24:27+00:00 2026-05-27T14:24:27+00:00

I have Struts 1 action and want to test it in isolation. What this

  • 0

I have Struts 1 action and want to test it in isolation.
What this action do is as follows:

  • load data using parameters from request
  • build xml-based representation of this data
  • send this response directly to client

I use jMock for testing but have one doubt here.
My first test is

public void shouldActionInvocationPrintValidResponse() {
    ProcessingAction action = new ProcessingAction();

    DBService service = mock(DBService.class);
    List records = new ArrayList();
    when(service.loadData()).thenReturn(records);

    ResponseBuilder builder = mock(ResponseBuilder.class);
    when(builder.buildResponse(records)).thenReturn("fake response");

    action.execute(null, null, null, null);

    assertEquals("fake response", writer.getContentWritten());
}

And my prod code evaluated to this:

public String execute(...) {
    List recordsList = service.loadData();
    String response = responseBuilder.buildResponse(recordsList);
    response.getWriter().print(response);
}

My doubt here is if such test isn’t too big here. I check whole succesful flow here. Shouldn’t there be separate tests for checking every single dependency call in their own tests?

I wonder because I had troubles with this test’s name. My ideas at the beginning were something like

shouldFetchDataThenFormatThemAndSendResponse

As this is all the tests does, the name shows it probably does too much (look at the “and” e.g. in the test name)

And should I have whole test written at once, or just add dependencies calls step-by-step?

EDIT:
Detailed code for test and action provided.

  • 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-27T14:24:28+00:00Added an answer on May 27, 2026 at 2:24 pm

    I think you are on the right track. shouldFetchDataThenFormatThemAndSendResponse This says it all. In your test naming you are talking about implementation details. This is how your first test should have been written.

    ProcessingAction action = new ProcessingAction();
    
    Response response = action.execute();
    
    assertEquals(true, response.IsValid);
    

    Try: shouldGetResponseWhenActionExecuted.

    Now you can look at how to get a response when executing an action.

    I would bet you dollars to donuts that you didn’t TDD this.

    Remember: Intent over Implementation! Stop showing your crusty underwear.

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

Sidebar

Related Questions

I want to generate xml file from Struts action object. So that I have
I'm using Struts 1. I have an Action, and when this Action forwards to
I have a simple Action class which I want to unit test: package com.gam.action.test;
i have a struts action that's have a doc as response this is the
I have an Action, called ShowData that recovers data from the database and put
I am using Struts 2. I have a JSP. It has this code: <span
I have a model-driven Struts Web action: public class ModelDrivenAction<T extends Object> implements ModelDriven<T>,
In my struts.xml I have: <action name=file_save method=fileSave class=FileActionBean> <interceptor-ref name=fileUpload> <param name=maximumSize> 5242880
I have started using struts .I have hanged in a place ,Code is bellow
I'm using Spring and struts and have the following entry in '/META-INF/context.xml' <Context cachingAllowed=false

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.