-1

I got the following code:

enter image description here

in the textbook that I am reading it says that for an infection to occur, mutation delta 1, it should be that the value of A must be different from the value of B. At this point I get lost, for what I know the infection condition in mutation testing appears when there is a change in the state of a program.

In the mutated code this infection is happening because when A is different to B, that would compromise the if section that says if b<minVal? in that case, what is the real meaning of infection in mutation testing? Please if someone can provide some examples it would be great.

Thanks

1
  • 1
    It's going to be difficult to answer this question without more context from the book. Jun 10, 2018 at 15:51

1 Answer 1

3

for an infection to occur, mutation delta 1, it should be that the value of A must be different from the value of B. At this point I get lost

The textbook in question seems to mean that if B == A, changing minVal = A to minVal = B does not actually mutate anything in the state of the program, because the mutation would be equivalent to the original.

As you say: "the infection condition in mutation testing appears when there is a change in the state of a program." - when the mutation is equal to the original, such as when mutating a variable into an equal other variable, no actual state alteration has occurred.

What is the real meaning of infection in mutation testing?

Infection testing is essentially a test of your test suite. By running infection tests, you run your unit tests against a slightly mutated version of the code it supposedly tests. If the mutated code passes your tests, you may have some brittle tests in your suite: apparently your tests pass even when the code does not do what it is expected to do!

A simple example of infection testing would be this sample test:

assert(!3.isGreaterThan(3));

Implemented like such:

return this > input;

This extremely oversimplified example would produce a 100% code coverage in terms of executed lines during the testing process.

A mutation testing framework, however, would quickly notice that the following would also pass:

return this < input;

The mutation, which completely changed the intention of the method in question, passes the test. Therefore, the test does not fail when the intentions and expectations of the code are not met.

It's important to note that only the mutations that actually change the intent of the code are "real" mutations: a mutation that would see the tests pass when changing the code into the following is not infected:

return input < this;

Edit: It's probably important to notice that in the textbook example, delta 1, 2, 3, 4, 5 and 6 are each a separate mutation on their own. Given the example, when running an infection test suite, then the tests will be executed 6 times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.