samedi 28 juillet 2018

How to identify fields that were accessed or changed during a method execution without existing code modification

This is for testing purpose. I am trying to figure out during a method execution, how to identify fields that were accessed or modified. The fields can be public, private, from the object's superclass, parent class, outer class, etc.

For example, I have some code written by someone else, bottom line, I am not allowed to modify their code or at least the existing data structure of its classes. And they did not use setter and getter for most of the field changes. Adding a few lines of code at the beginning of a method and before the return is allowed for invoking my own implemented listener method.

public class MyClass {
    public String field1;
    public MyOtherClass field2;
    public String[] field3;

    public void method1(){
        field1 = "changed"; //field changed
        String st = field1; //field accessed
    }
}

Any recommendations?





Aucun commentaire:

Enregistrer un commentaire