模拟对象返回NPE


@SpringBootTest
@RunWith(MockitoJUnitRunner.class)
public class EmpCompSTest {
@Mock
private CompCl compCl; 
@Test
public void testGetEmpCompS() {
EmpRequest request = new EmpRequest();
Map<Long, List<CompCl.CompeSc>> comp = new HashMap<>();
CompCl.CompSc compSc1
= new CompCl.CompSc(); 
comp.put(1L, Arrays.asList(compSc1));
when(compCl.getUsrSc(request.getComp().keySet())).thenReturn(comp); 
}
}

调试时,在带有when()的行上弹出NullPointerException,类compCLnull

这是木星吗?在这种情况下,使用@ExtendWith(MockitoExtension.class)而不是@RunWith(MockitoJUnitRunner.class)

应该为EmpRequest设置Comp

最新更新