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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:47:49+00:00 2026-05-31T13:47:49+00:00

I am trying to run the EasyMock example given here with TestNG and am

  • 0

I am trying to run the EasyMock example given here with TestNG and am facing a strange issue. The first two tests run fine but the third Test (getPriceDataAccessThrowsRuntimeException) runs successfully if I run it alone. However, when I run it with other two test either individually or all together the third test fails and I get the following:

FAILED: getPriceDataAccessThrowsRuntimeException
org.testng.TestException: 
Expected exception java.lang.RuntimeException but got org.testng.TestException: 
Expected exception java.lang.RuntimeException but got java.lang.AssertionError: 
  Unexpected method call DataAccess.getPriceBySku("3283947"):

Following is the Test code:

@Test
public void getPrice() throws Exception {
    // Set expectations on mocks.
    expect(mockedDependency.getPriceBySku(SKU)).andReturn(new BigDecimal(100));

    // Set mocks into testing mode.
    replay(mockedDependency);
    final BigDecimal price = systemUnderTest.getPrice(SKU);
    assertNotNull(price);

    // Verify behavior.
    verify(mockedDependency);
}

@Test(expectedExceptions = MyCustomException.class)
public void getPriceNonExistentSkuThrowsException() throws Exception {

    // Set expectations on mocks.
    expect(mockedDependency.getPriceBySku(BAD_SKU)).andReturn(null);

    // Set mocks into testing mode.
    replay(mockedDependency);
    final BigDecimal price = systemUnderTest.getPrice(BAD_SKU);
}

@Test(expectedExceptions = RuntimeException.class)
public void getPriceDataAccessThrowsRuntimeException() throws Exception {

    // Set expectations on mocks.
    expect(mockedDependency.getPriceBySku(SKU)).andThrow(new RuntimeException("Fatal data access exception."));

    // Set mocks into testing mode.
    replay(mockedDependency);
    final BigDecimal price = systemUnderTest.getPrice(SKU);
}

Any idea guys, what am I doing wrong?

  • 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-31T13:47:50+00:00Added an answer on May 31, 2026 at 1:47 pm

    It looks like you’ve made a mistake when converting from JUnit to TestNG. In the linked example, the doBeforeEachTestCase method is run before each test case and this resets the mocked dependency to its base state. You haven’t included all the code: you should have doBeforeEachTestCase annotated with BeforeMethod to run it with TestNG.

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

Sidebar

Related Questions

I'm attempting to write some unit tests using EasyMock and TestNG and have run
Trying to run Jison unit tests, but the command fails. How do I fix
Situation: I'm trying run an https store (xcart) under one domain secure.example.com and I
I am trying to run the VS 2008 SP1 installer , but it says
Trying to run the reportviewer with passing the parameter but receive error: Validation of
When trying to run the sample code here: http://www.nikhilk.net/Live-Search-REST-API.aspx I get: Error 52 The
I wrote this C program for Win32/c compiler but while i'm trying run this
Trying to run the basic examples given by playn, wanting to have a go
trying to run this basic form control example on msdn. At step 1 of
When trying run this code: At first it prints Process some_id BEFORE enter for

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.