我需要你们的一点帮助。
我想对此代码进行测试:
//Delete - Patient
void deletePatient(long id) throws PatientNotFoundException {
long deletedRecord = clientWrapperWrite.deleteSingle(PATIENT_COLLECTION_NAME, id);
if (deletedRecord == 0) {
throw new PatientNotFoundException(id);
}
}
这是我为测试所做的
//Delete Patient TestUnit - OnProgress (SOS)
@Test
public void deletingEmptyPatient() throws PatientNotFoundException, IOException {
MongoClientWrapper mockClientWrapperWrite = mock(MongoClientWrapper.class);
MongoClientWrapper mockClientWrapperRead = mock(MongoClientWrapper.class);
Patient dummyPatient = createSinglePatient();
myPatientFacade = MyPatientFacadeBuilder.create("conf/mypatient-server-test.properties")
.withMongoClientWrapperRead(mockClientWrapperRead)
.withMongoClientWrapperWrite(mockClientWrapperWrite)
.build();
myPatientFacade.addSinglePatient(dummyPatient);
myPatientFacade.deletePatient(10001L);
ArgumentCaptor<Long> patientIdCaptor = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<String> collectionNameCaptor = ArgumentCaptor.forClass(String.class);
verify(mockClientWrapperWrite,times(1))
.deleteSingle(collectionNameCaptor.capture(),patientIdCaptor.capture());
}
这就是调试器告诉我的内容:
关于职务:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
这是调试器告诉我的:They said i dont insert the person, but using the function before delete i add the person
我仍在学习如何使用JUnit和Mockito学习。请指导我。谢谢您的光临,祝您有个美好的一天
请使用H2或HSQL,并在存储库层测试用例上准备单独的层,而不是来自控制器层。
遵循步骤
乐于助人]