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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:52:16+00:00 2026-05-22T18:52:16+00:00

I have a test class with two methods annotated as @Test. If i run

  • 0

I have a test class with two methods annotated as @Test.

If i run each methods individually by commenting the other, it succeeds. But if run both together, it fails. What could be the reason?

public class ProductAvailTest {
private static final String PRODUCT_AVAIL_BUILDER = "ProductAvailBuilder";


@Test
public void productAvailResponseDateRequired() throws Exception {

    ResponseBuilderFactory responseBuilderFactory = ResponseBuilderFactory.createResponseBuilderFactory();
    ResponseBuilder responseBuilder = responseBuilderFactory.createResponseBuilder(PRODUCT_AVAIL_BUILDER);
    ProductAvailDateRqdHelper productAvailDateRqdHelper = new ProductAvailDateRqdHelper();
    List<Rsproducts> products = productAvailDateRqdHelper.getLOMProducts();

    // TODO change this to logger
    System.out.println("No. of products in test " + products.size());

    GetProductAvailOutput actualProductAvailOutput = (GetProductAvailOutput) responseBuilder.buildSuccessResponse(
            products, productAvailDateRqdHelper.getProductAvailInput());
    GetProductAvailOutput expectedProductAvailOutput = productAvailDateRqdHelper.getProductAvailOutput();

    // TODO change this to logger
    System.out.println("Size in expected " + expectedProductAvailOutput.getProductBrand().size());
    System.out.println("Size in actual " + actualProductAvailOutput.getProductBrand().size());

    Assert.assertEquals(expectedProductAvailOutput, actualProductAvailOutput);

}


@Test
public void productAvailResponseInvBased() throws Exception {
    ResponseBuilderFactory responseBuilderFactory = ResponseBuilderFactory.createResponseBuilderFactory();
    ResponseBuilder responseBuilder = responseBuilderFactory.createResponseBuilder(PRODUCT_AVAIL_BUILDER);
    ProductAvailInvHelper productAvailInvHelper = new ProductAvailInvHelper();
    List<Rsproducts> products = productAvailInvHelper.getLOMProducts();

    // TODO change this to logger
    System.out.println("No. of products in test " + products.size());

    System.out.println("No of inventory " + products.get(0).getRsproddtls().size());


    GetProductAvailOutput actualProductAvailOutput = (GetProductAvailOutput) responseBuilder.buildSuccessResponse(
            products, productAvailInvHelper.getProductAvailInput());
    GetProductAvailOutput expectedProductAvailOutput = productAvailInvHelper.getProductAvailOutput();

    // TODO change this to logger
    System.out.println("Size in expected " + expectedProductAvailOutput.getProductBrand().size());
    System.out.println("Size in actual " + actualProductAvailOutput.getProductBrand().size());


    Assert.assertEquals(expectedProductAvailOutput, actualProductAvailOutput);
}




@Test
public void productAvailResponseFreeSell() throws Exception {

    ResponseBuilderFactory responseBuilderFactory = ResponseBuilderFactory.createResponseBuilderFactory();
    ResponseBuilder responseBuilder = responseBuilderFactory.createResponseBuilder(PRODUCT_AVAIL_BUILDER);
    ProductAvailFreeSellHelper productAvailFreeSellHelper = new ProductAvailFreeSellHelper();
    List<Rsproducts> products = productAvailFreeSellHelper.getLOMProducts();

    // TODO change this to logger
    System.out.println("No. of products in test " + products.size());

    GetProductAvailOutput actualProductAvailOutput = (GetProductAvailOutput) responseBuilder.buildSuccessResponse(
            products, productAvailFreeSellHelper.getProductAvailInput());
    GetProductAvailOutput expectedProductAvailOutput = productAvailFreeSellHelper.getProductAvailOutput();

    // TODO change this to logger
    System.out.println("Size in expected " + expectedProductAvailOutput.getProductBrand().size());
    System.out.println("Size in actual " + actualProductAvailOutput.getProductBrand().size());

    Assert.assertEquals(expectedProductAvailOutput, actualProductAvailOutput);

}

}

  • 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-22T18:52:17+00:00Added an answer on May 22, 2026 at 6:52 pm

    I would hazard a guess that the test methods are not setting up their environment independently. So the first test within a given java invocation works, but leaves the environment in a different state that’s not suitable for the next test run.

    If you’re setting up important state within static initialiser blocks, or possibly within the constructor of the test, you may fall foul of this. Important state should be initialised either as local variables within the test method, or via methods annotated with @Before.

    You should expand on what “it fails” means – is it the second of the two tests that fails by any chance, while the first to run succeeds?

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

Sidebar

Related Questions

I have two classes (A and B) which depend on each other in following
I have a chat class with two methods: updateChat and sendChat. //chat.js var state;
I have a Junit test class with two tests in it. test 1 will
I have two classes (class A and B) both marked with [Binding]. Currently I'm
I have a handful of controllers and each controller has a test class with
Given I have a class with two constructors: public class TestClass { ObjectOne o1;
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired
say I have: class Test { public static int Hello = 5; } This
I have a JUnit test class in which I have several static final int
If I have a class called Test :: class Test { static std::vector<int> staticVector;

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.