Consider the following pseudo code. It is intended to determine if a class is a passed class.
class Student: int grade boolean IsStudentPassing(): return grade >= MIN_PASSING_GRADE ...
If we wrote unit test for IsStudentPassing , we could use a constant value:
ensure that IsStudentPassing is false when grade is MIN_PASSING_GRADE - 1 ensure that IsStudentPassing is true when grade is MIN_PASSING_GRADE
Or we could manually select the values:
ensure that IsStudentPassing is false when grade is 69 ensure that IsStudentPassing is true when grade is 70
For the second approach, our test should be rewritten if MIN_PASSING_GRADE changes. The first approach is more flexible, but relies on MIN_PASSING_GRADE , which has the correct value.
I'm not quite sure which approach prefers, and generally choose in each case. On the one hand, to ensure that MIN_PASSING_GRADE normal, you should take care of another test. On the other hand, I am worried about the supposedly “single” test involving too many other places in the code base.
This is a contrived example, but similar situations are often found in real programs. What is the best approach to solve them?
source share