如何用私有变量编写方法的jUnit测试用例

时间:2016-06-11 08:33:31

标签: java junit private

    private PreconfigGroupOpenLPolicyRulesService openlApi;

@Override
public Object[] getPackageEligibility(IRulesRuntimeContext context, Dimension dimension) {
    return openlApi.PackageEligibility(context, dimension);
}

我是jUnits的新手。任何人都可以帮我写方法getPackageEligibility的测试用例。我需要做的就是@Mock。

我试过

PreconfigGroupOpenLComponentService preconfigGroupOpenLComponentService = new PreconfigGroupOpenLComponentService();

@Mock
PreconfigGroupOpenLPolicyRulesService openlApi;
@Mock
IRulesRuntimeContext context;
@Mock
Dimension dimension;



@Test
public void testGetPackageEligibility() {

    Object[] arg = preconfigGroupOpenLComponentService.getPackageEligibility(context, dimension);
    assertNotNull(arg);

}

但是

显示java.lang.NullPointerException     at com.exigen.eis.preconfig.policy.group.services.impl.PreconfigGroupOpenLComponentService.getPackageEligibility(PreconfigGroupOpenLComponentService.java:32)     at com.exigen.eis.preconfig.policy.group.services.impl.PreconfigGroupOpenLComponentServiceTest.testGetPackageEligibility(PreconfigGroupOpenLComponentServiceTest.java:28)

0 个答案:

没有答案