3

In boundary analysis testing, some authors suggest testing MIN-1, MIN, MIN+1 (and the same for MAX).

Also for 1-100 range (if A>=1 && A<=100), test cases would be: 0,1,2 and 99,100,101.

I do not see the point - if 100 works, then 99 must work too (in my opinion but this is why I ask).

1

2 Answers 2

7

Lets assume you are testing a class "interval", representing intervals of natural numbers:

 var interval= new Interval(1,100); 

Now your first two tests are "green":

AssertIsTrue(interval.Contains(100)) AssertIsFalse(interval.Contains(101)) 

and you are confident the author made no "off-by-one-error".

Unfortunately, the implementation looks like this

Contains(x) { return (x>= beginRange && x == endRange); // above line has a typo, "==" should have been be "<=" } 

So you were better off to add another test at first hand,

 AssertIsTrue(interval.Contains(99)); 

which fails, revealing the bug missed by the first two tests.

Or to be more general: off-by-one errors do not always manifest themselves by mixing up "<" and "<=", there are lots of other possibilities to get such things wrong, and as a tester, you are better off not to make any assumptions about how the internal implementation of a function looks like.

3
  • Hmm, how could 101 pass if X==end range and the range is 1-100? Commented Jan 24, 2015 at 13:14
  • @user144171: read the code carefully twice, then you will probably understand. Commented Jan 24, 2015 at 13:41
  • 1
    @user144171 That's exactly the reason to test it :-) Commented Jan 24, 2015 at 18:28
0

In boundary analysis testing, some authors suggest testing MIN-1, MIN, MIN+1 (and the same for MAX) ... I do not see the point

The point is that your code is expected to fail for values outside the permitted range and that's what you're testing with these "extra" cases.
Not every test should pass; you need to test for [some] things that you would expect to fail - and correct the problem if/when they don't.

1
  • I don't think he meant why test min-1, he meant why test min+1, a value inside the permitted range. Commented Dec 13, 2016 at 12:41

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.