Saturday, April 19, 2025

Software Testing Mutation Operators Example Codes

 Software Testing Mutation Operators Example Codes (SKD)Super Keyword Deletion

class A{

    int a;

    void show(){

        System.out.println(a);

    }

}


class B extends A{

    int a;

    void setA(int a_){

       super. a = a_; // If we delete the super keyword 

    }

}

public class Main{

public static void main(String[] args) {

B ob = new B();

    ob.setA(10);------>Acessed from parent class A , hence the output is 0 instead of 10

ob.show();

}

}

Mutation Testing is a method to evaluate the quality of software tests. A mutation operator introduces small changes (mutations) in the code to check if the existing tests can catch the errors.

The Super Keyword Deletion (SKD) operator removes the super keyword, which refers to a member of the parent class from the child class

Class A has an integer variable a and a method show() that prints it.

Class B inherits from class A,It also declares its own variable a (this hides the parent’s variable a).
  • In setA(), the statement super.a = a_; means:

  • "Set the value of the variable a in the parent class A to a_."

Mutation: If We Delete the super Keyword
Now it will set B's own a, not A's. So, when ob.show() is called, it prints A's a, which is still 0 (the default value for an int).


Original Code Output: 10(Because super.a = 10; sets parent class's variable)

Mutated Code Output: (Because a = 10; sets B's variable, not A's. A’s variable remains unchanged)



No comments:

Post a Comment

Mangerial Economics Quiz1 solutions Guide

Mangerial Economics Quiz1 solutions Guide  solutions watch on you tube channel