EvoSuite / evosuite

EvoSuite - automated generation of JUnit test suites for Java classes
http://www.evosuite.org
GNU Lesser General Public License v3.0
823 stars 341 forks source link

Refactor in variable naming strategy #441

Closed 4everTheOne closed 1 year ago

4everTheOne commented 1 year ago

Hi, this is a small PR that opens a new path by allowing the developers to change the variable naming strategy.

Let's consider the following example with the current implementation. At the moment, when a new Unit test is generated by EvoSuite, they look something like this:

Short[] shortArray0 = new Short[5];
Short short0 = shortArray0[0];

What If the user would prefer another naming? Something completely different? Like:

Short[] var0Array = new Short[5];
Short var1 = var0Array[0];

This can now be achieved by only creating a new VariableNameStrategy. For example, the example shown can be implemented with:

public class SimpleVariableNameStrategy extends AbstractVariableNameStrategy {
    @Override
    public String createNameForVariable(VariableReference variable) {
        if (variable.isArray()) {
            return variable.getName() + "Array";
        } else {
            return variable.getName();
        }
    }
}

Please let me know your thoughts/suggestion about it!