2

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?

henry
  • 5,923
  • 29
  • 46
CryoMancer
  • 23
  • 1
  • 4
  • 1
    Hint: varriable names go camelCase, even when they are just one char and example code ;-) – GhostCat Oct 19 '16 at 03:59
  • Given your comment on my answer ... it gets more complicated. So, the first thing you want to do: turn to the helpcenter to read about "how to ask". You see, you are telling us that something isnt working. But you are not giving any relevant details. Like: what tools you are using, which version ... Long story short: if you want us to help, you should provide a minimal, complete and viable example in your question - so that people have a chance understanding where your setup is broken. As is, your question can **not** be answered. – GhostCat Oct 19 '16 at 10:37
  • And as tip: in case *other* pieces of code can be killed; maybe you have to to look into differences there. – GhostCat Oct 19 '16 at 10:41
  • @GhostCat Okay i got your point .i am using eclipse-jee-mars-2-win32-x86_64 and PIT Tool for Mutation Testing .Have also provided you the test case and approach which i am using . So i think it will be enough for you to answer my question.!!!!!!!!!!! – CryoMancer Oct 20 '16 at 03:33
  • I would suggest: see if you can repro this behavior with as few code as possible. You see, you only **outlined** your code under test; and you only showed one testcase. I would say: go for some experiments and as few lines as possible. And then you might also reach out to the folks providing that tooling. I am sure that they have support forums, too. – GhostCat Oct 20 '16 at 06:30

2 Answers2

1

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!

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • yes i have the test that invokes the method with null. my test case is:- – CryoMancer Oct 19 '16 at 10:04
  • @Test(expected=NullPointerException.class) public void testForvalidation(){ testObject.method1(null); } but still i am not able to kill the mutation. – CryoMancer Oct 19 '16 at 10:06
  • 2
    Does the test fail if you comment out the ValidateArgument.notNull(B); line? – henry Oct 19 '16 at 12:17
  • 1
    Seems that even if you manually remove ValidateArgument.notNull(B) you still get NullPointerException later in the method. – Boris Oct 19 '16 at 12:43
  • @Boris yes i checked the code and found that even after removing the ValidateArgument.notNull(B) , i am getting "NullPointerException" from the line where B has been used . So is there any way i could kill this mutation..? – CryoMancer Oct 20 '16 at 03:28
  • In that case this validator does nothing for you. I would simply remove it. – Boris Oct 20 '16 at 09:00
1

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.

henry
  • 5,923
  • 29
  • 46
  • Thank you for your comments. i have used ValidateArgument.notNull(B); to avoid the unneeded execution of my code. if someone would invoke my method with null in that case rather than executing the code and waiting for the line that will give me NullPointerException My code will simply give me exception at the starting and will save my processing time . this was the only thing why i have used this. – CryoMancer Oct 21 '16 at 06:26