JSP
JSP

Reputation: 587

jmockit verifications block throwing Missing 1 invocation to methodName

Am trying to run one test case which will update the data into DB. This is my source code of test method.

@Tested // This is class-level scope as I have different test methods.
FirstLevelClass firstLevelClass;

@Test
public void testUpdateDB(@Mocked SecondLevelClass secondLevelClass) throws Exception {

        // Updated method by passing an argument.
        firstLevelClass.updateDatabaseThroughSecondLevelClass(info);

        new Verifications() {{
            SecondLevelClass.updateDB(creds, data);
            times =1;
        }};

Here my intention is to verify the expected invocations to mocked methods[which recorded in expectations]. But, verifications block is giving the following exception message. If I remove times=1, then test case is getting success. That is not my desired result.Can anyone please suggest me what could be wrong in my test case.

mockit.internal.MissingInvocation: Missing 1 invocation to: SecondLevelClass#updateDB(creds, data) with arguments: creds, data

Caused by: Missing invocations

Updated Question :

There is one argument to updateDatabaseThroughSecondLevelClass(info), from that argument we are forming creds reference in SecondLevelClass.

Credentials creds = info.getCredentials();

But in verifications block[Which is part of FirstLevelClass] we have created locally test object.

Credentials creds = getCredsTestObject();

This is the reason why it complained about Missing invocations. Because both are two different references in two classes. Can anyone please suggest me how to handle this case.

Thanks In Advance.

Upvotes: 0

Views: 3660

Answers (1)

juherr
juherr

Reputation: 5740

It is a known issue in the integration between TestNG and JMockit: https://github.com/jmockit/jmockit1/issues/337

Upvotes: 0

Related Questions