mercredi 31 août 2016

JMockit mock not getting destroyed

Have a class TestAccess.java having

static private TestAccess instance = new TestAccess ();
public static TestAccess getTestAccess() {
                returns instance;
            }

For testing a test class A.java used jmockito to mock the getTestAccess method

 new MockUp<TestAccess>() {

    @mock
    TestAccess mockTestaccess;

                @mockit.Mock
                public TestAccess getTestAccess() {
                    return mockTestaccess;
                }
}

In another class B.java i dont want to use mock and call TestAccess.java as follows

TestAccess.getTestAccess()

B.java of run independently the real TestAccess instance is returned and works fine.

However during maven run it fails as even in B.java the TestAccess.getTestAccess() return the mock defined in A.java and not the real instance as expected.

Could anyone guide how can this be resolved.

Thanks

Aucun commentaire:

Enregistrer un commentaire