简体   繁体   English

为没有参数的受保护的void方法编写Junit

[英]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. 为没有参数的受保护的void方法编写一个Junit测试用例,它什么也不做。

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

Now, I want to write a Junit for init() method which does nothing apart from initialization. 现在,我想为Junit init()方法编写一个Junit,它除了初始化外没有其他作用。 Any help is appreciated. 任何帮助表示赞赏。 Thanks in advance. 提前致谢。

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());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM