CryoMancer
CryoMancer

Reputation: 23

Mutation killing

I am stuck at 1 point and need suggestions.

While writing junit for my code I'm not able to kill the ValidateArgument.notNull(arg1) mutation !!!
Need Suggestions.

code follows as..

public class A{

  public void method1(Object B){

          ValidateArgument.notNull(B);
          ..
          ..
          ..
  }
}

Getting

## removed call to com/nokia/oss/configurator/rac/common/util/ValidateArgument::notNull → SURVIVED

as return type is void what could be the possible ways to kill this mutation?

Upvotes: 2

Views: 3437

Answers (2)

henry
henry

Reputation: 6096

What is the purpose of ValidateArgument.notNull(B); ?

We know from your test that it throws a NullPointerException when passed null, is that all it does that you care about?

If so you should delete that line of code as it is useless - you will still get a NullPointerException when you call method1. i.e. the behaviour your test specifies is the same.

Or perhaps ValidateArgument.notNull does something else important to you? Maybe it generates an exception message that you find useful? If so you need to write a test that confirms that message is present.

However many programmers do not write tests that specify the behaviour of assertions such as this (whether it makes sense to do so will depend on the context/domain you are working in).

Pitest has a feature that allows you to avoid creating mutations in concerns that are not usually unit tested (the other common one being logging).

If you add full.package.name.ValidateArgument to the avoidCallsTo configuration parameter this mutation will no longer be produced.

Upvotes: 1

GhostCat
GhostCat

Reputation: 140467

Guessing here: do you have a test that invokes the method with null for B?

You see, most likely, that validation method should throw an exception when B is null. When you never test the method with null, it doesn't make a difference if that one line is really executed or not!

Upvotes: 1

Related Questions