Junit:编写单元测试案例以将学生从组中删除

时间:2019-05-14 03:34:40

标签: java unit-testing junit automated-tests

正在测试功能[ { "hospitalNumber": null, "patientName": null, "totalAmount": 31104 }, { "hospitalNumber": "", "patientName": "LastName, FirstName", "totalAmount": 3439.8 } ] ,其中预期的行为是如果removeStudent(Student s, Group g)为空,则调用Group不会有任何作用。

我们如何测试这种行为?

以下是一些方法:

removeStudent

仅能编写一个测试用例:

private final Map<Group, Set<Student>> studentsInGroup = new HashMap<>();

public void removeStudent(Student s, Group g) {

    Collection<Student> students = getStudentsInGroup(g);

    studentsInGroup.remove(s);
}

public Collection<Student> getStudentsInGroup(Group g) {

    Collection<Student> students = studentsInGroup.get(g);
    if (students == null) {
        students = new HashSet<Student>();
    }

    return students;
}

这是测试要求的正确案例吗?我还可以添加什么测试?

0 个答案:

没有答案