KrunalParmar
KrunalParmar

Reputation: 1114

µJava Is not killing Mutants?

i am using µJava for mutation testing of my java program. as i am learning mutation testing.

i have 2 classes

1 : Parent

public class Parent 
{
public String temp;
public int number;

public Parent(String temp)
{
    this.temp = temp;
    this.number = 20;
}

public String printTemp()
{       
    return "temp is : "+temp+number;
} 
} 

and 2 : Child

public class Child extends Parent
{
public int number;

public Child(String temp)
{
    super(temp);
    this.number = 5;
}

public String printTemp()
{
    String temp = "i am fake !";
    int number = 766;
    return "temp is : "+super.temp+this.number+"c";
}
}

and i am applying IOD operation of muJava. `hence it is generating mutant . it is deleting overridden method printTemp of child class.

my TestCase is :

public class MyTest
 {
    public String test1 ()
      {  
      String result;

     Parent p1 = new Parent("i am temp of parent");

      Child c1 = new Child("i am temp of child");

      Parent p2 = new Child("i am both !");

      result = ""+ c1.printTemp() + p1.printTemp() + p2.printTemp(); 

      return result;
      }
   }

But when i am running Mutation Testing , i have found the mutant lived. i want to kill it ! What can i do ??

Upvotes: 1

Views: 427

Answers (1)

Rene Just
Rene Just

Reputation: 81

MuJava has switched its testing infrastructure to JUnit (see https://cs.gmu.edu/~offutt/mujava/, Section III.3). This means that you should write a JUnit test, which not only covers the code but also asserts on the result.

Example:

@Test
public void testPrintTempChild() {
    Child c = new Child("Child");
    String actual = c.printTemp();
    String expected = "temp is : Child5c"; 
    assertEquals(expected, actual);
}

@Test
public void testPrintTempParent() {
    Parent p = new Parent("Parent");
    String actual = p.printTemp();
    String expected = "temp is : Parent20";
    assertEquals(expected, actual);
}

If you apply the IOD mutation operator, the first test should detect that mutant (i.e., it should fail because printTemp returns "temp is : Child20").

As an additional comment, the reference p2 in your test code is also an instance of Child, so c1.printTemp() and p2.printTemp() both invoke the method printTemp in your class Child.

Upvotes: 1

Related Questions