0

If I had the following code

public static <T> int count(List<T> list, T elem) {
  int count = 0; // the result
  for (int i=0; i < list.size(); i++) {
  if (list.get(i).equals(elem))
  count++;
  }
 return count;
}

Lets say I need to run a black box test,

Like so,

Input

[null], null Output should be 0

Firstly, is this a worthwhile test case? ( for black box testing)

If not,

Then I ask, are null values worth while tests for black box testing in any case?(in general)

Thanks

Jim
  • 482
  • 1
  • 5
  • 20

1 Answers1

2

How code reacts to null inputs is something that should be documented and tested, yes.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • 1
    It doesn't hurt. And, it documents for the reader that `null` is permissible as an argument. Why not use a foreach loop though? – Eric Jablow Jun 01 '13 at 02:36
  • Alright great, was kind of unsure as to whether they were worthwhile or not – Jim Jun 01 '13 at 02:37
  • +1 for "use a foreach loop". If that is a non-random-access list, then access by index might be quite slow. – Thilo Jun 01 '13 at 02:39
  • Oh that isn't my code it was just the example in a text book, I was more wondering the best way to structure black box tests... But I can see how a for each would be more appropriate – Jim Jun 01 '13 at 02:44