作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我为 flex 搜索CRUD操作创建了一个JUNIT测试用例,下面给出了代码。在代码审查阶段之后,我得到了团队的更新,我已经涵盖了测试用例的所有积极场景,但仍然没有涵盖消极场景。我不知道如何处理负面用例。
@Test
void findById() throws Exception {
EmployeeInformation EmployeeGet = Eservice.findById("elcrud", "2");
assertNotNull(EmployeeGet.getId());
assertNotNull(EmployeeGet.getFirstName());
assertNotNull(EmployeeGet.getLastName());
}
@Test
void deleteProfileDocument() throws Exception {
String Result = Eservice.deleteProfileDocument("elcrud", "3");
System.out.println(Result);
assertEquals(Result, "DELETED");
}
@Test
void search() throws Exception {
List<EmployeeInformation> Emp=Eservice.searchByTechnology("Lucidworks","elcrud");
System.out.println(Emp.size());
int Result = Emp.size();
assertTrue(Result >= 0 );
}
@Test
void searchByName() throws Exception {
List<EmployeeInformation> Emp=Eservice.findProfileByName("junit","elcrud");
System.out.println(Emp.size());
int Result = Emp.size();
assertTrue(Result >= 0 );
}
最佳答案
我认为您的技术团队需要测试ES的运行是否失败,没有结果或发生任何其他意外情况。
一个示例可能是删除配置文件:
如果删除操作成功,您已经完成了测试。但是您没有测试此操作是否失败或未成功处理。
@Test
void deleteProfileDocument() throws Exception {
//here you delete a profile which is NOT in the index
String Result = Eservice.deleteProfileDocument("elcrud", "3");
System.out.println(Result);
//and here you asssert the negative result. (Not sure which result will come)
assertEquals(Result, "NOT_FOUND");
}
@Test(expected = YourExpectedException.class)
Exception exception = assertThrows(YourExpectedException.class, () -> {
Eservice.findProfileByName(Exception values);
});
String expectedMessage = "expected message";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
@Test
void testUpdateItem_POSITIVE() throws Exception {
....
}
@Test
void testUpdateItem_NEGATIVE() throws Exception {
....
}
关于spring-boot - 如何为Elasticsearchn CRUD操作处理否定的JUNIT测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60107953/
我是一名优秀的程序员,十分优秀!