Goutham
Goutham

Reputation: 1

Write a Junit for a protected void method without arguments

Write a Junit test case for a protected void method without arguments, which does nothing.

protected void init() {
    i=10;
    j=20;
}

Now, I want to write a Junit for init() method which does nothing apart from initialization. Any help is appreciated. Thanks in advance.

Upvotes: 0

Views: 204

Answers (1)

Progman
Progman

Reputation: 19545

If you want to check that the fields are set after the initialization you do exactly that.

@Test
public void fieldAreInitialized()
{
    YourClass x = new YourClass();
    x.methodWhichCallsInit();

    Assert.assertEquals(10, x.getI());
    Assert.assertEquals(20, x.getJ());
}

Upvotes: 2

Related Questions