user5019310
user5019310

Reputation:

mutation testing reachability infection and propagation

Hey guys i have a question about mutation testing here is the sample code

//Effects: If numbers null throw NullPointException
// else return LAST occurance of val in numbers[]
//If val not in numbers [] return -1
 
public static int findVal (int numbers[], int val)
{
 int findVal = -1;
for( int i = 0 ;  i < numbers.length ; i++)     // for( int i = 1 ;  i < numbers.length ; i++)
 
if( numbers[i] == val)
findVal = i;
return (findVal);
}
 

(a) If possible, find a test input that does not reach the mutant.

(b) If possible, find a test input that satisfies reachability but not infection for the mutant.

(c) If possible, find a test input that satisfies infection, but not propagation for the mutant.

(d) If possible, find a test input that kills mutant.

Upvotes: 2

Views: 3812

Answers (1)

Rene Just
Rene Just

Reputation: 81

You didn't include a definition for reachability, infection, and propagation in your question -- I am assuming the following:

  • reachability: execution of the mutated expression
  • infection: the value of the mutated expression differs from the value of the original (unmutated) expression
  • propagation: the infected state (different expression value) leads to infection of an observable state

Also note that (d) not only depends on the input but also on the test oracle -- achieving propagation does not imply killing the mutant.

The following inputs satisfy your requirements:

(a) There exists no such input; the loop initializer int i = 0 is executed for every input, even if numbers is null and consequently numbers.length raises a NullPointerException. Note that only a test that does not call the findVal method can't reach the mutant -- calling findVal implies satisfying reachability for this mutant.

(b) There exists no such input; the mutated expression is independent of the method parameters (i=0 != i=1 for any input) -- satisfying reachability implies satisfying infection for this mutant.

(c) numbers is an empty array; if numbers.length is 0, then the initial value of i (for any i>=0) doesn't matter, even though the state of i is infected. Passing in null for numbers is another example that satisfies infection but not propagation.

(d) numbers is a one-element array, whose element value equals val. There are many inputs that satisfy propagation, which means that the mutant can be killed -- whether the test actually kills the mutant depends on whether the test asserts on the outcome.

Upvotes: 2

Related Questions