这些是我现在正在尝试测试的方法。
public void addGrade(String newGrade) {
if (numGrades >= grades.length) {
increaseGradesCapacity();
}
grades[numGrades] = newGrade;
numGrades++;
}
public void increaseGradesCapacity() {
String[] newGrades = new String[grades.length + 1];
for (int i = 0; i < grades.length; i++) {
newGrades[i] = grades[i];
}
grades = newGrades;
}
目前,我有一个测试用例,无需调用 increaseGradesCapacity() 方法即可进行测试:
@Test public void addGradeTest() {
String[] myGrades1 = {"a90", "a100", "q90", "q80",
"p100", "e87.5"};
String[] myGrades2 = {"a90", "a100", "q90", "q80",
"p100", "e87.5", "q100"};
WeightedGrades2 wg = new WeightedGrades2("Aegon Targaryen", 6, myGrades1);
wg.addGrade("q100");
Assert.assertArrayEquals("Test for addGrade.",
myGrades2, wg.getGrades());
}
但我试图弄清楚如何创建一个调用 increaseGradesCapacity() 方法的测试用例。这就是我现在所拥有的,但它仍然不能满足 Web-CAT 的要求。有人有想法么?
@Test public void addGradeTest2() {
String[] myGrades1 = {"a90", "a100", "q90", "q80",
"p100", "e87.5"};
String[] myGrades2 = {"a90", "a100", "q90", "q80",
"p100", "e87.5", null, "q100"};
WeightedGrades2 wg = new WeightedGrades2("Anakin Skywalker", 7, myGrades1);
wg.increaseGradesCapacity();
wg.addGrade("q100");
Assert.assertArrayEquals("Test for addGrade.",
myGrades2, wg.getGrades());
}