我对JUnit非常陌生。我写了一个简单的JUnit测试用例,它给出了NullPointerException
:
@RunWith(MockitoJUnitRunner.class)
public class ControllerTest {
@InjectMocks
Controller control;
@Mock
Service service;
@Test
public void postTest() throws IOException {
//Given
Object o = new Object();
//initialise the object here which the service layer would return
String a = "abcd";
Integer b = 5;
Mockito.when(service.Post(a,o)).thenReturn(o);
Mono<ResponseEntity<Object>> object = control.Post(a,o);
StepVerifier.create(object)
.consumeNextWith(entity -> {
assertEquals(b,entity.getBody().get());
})
.expectComplete();
在这种情况下,我得到一个NullPointerException
。