Gautham J
Gautham J

Reputation: 23

Static mocked objects in JMockit

Consider a test as below -

public class TestSomething
{
    @Mocked static SomeObject mocked;

    @Test
    public void testSomething()
    {
        new expectations() {{
            mocked.doSomething(); 
        }};

        callSomething(mocked);
    }
}

The issue is that mocked always turns out to be null because it is declared as static. Can this be overridden?

Upvotes: 0

Views: 113

Answers (1)

Rogério
Rogério

Reputation: 16380

No, @Mocked and the other mocking annotations only apply to instance fields of the test class (and to test method parameters as well).

Upvotes: 1

Related Questions