EvoSuite / evosuite

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

Using EvoSuite target_method #439

Open imesecan opened 1 year ago

imesecan commented 1 year ago

Context

I want to use EvoSuite to generate unit test for classes some of which have 10,000 methods. I know this is not realistic, but this is a test set to show some extremities. Luckily EvoSuite has target_method option which can help in such cases.

Steps to Reproduce

I see one example that talks about this option, but I couldn't find enough resources that can direct me to the proper use. For example I use the following class

import java.util.*;
class EvoDriver{
    public static int start(int num) {
        boolean h = num > 0;        
        if (deep1(h)) 
            return 1;
        return 0;
    }
    public static boolean deep1(boolean x) {
        return deep2(x);
    }
    public static boolean deep2(boolean x) {
        return deep3(x);
    }
    public static boolean deep3(boolean x) {
        return deep4(x);
    }
    public static boolean deep4(boolean x) {
        return deep5(x);
    }
    public static boolean deep5(boolean x) {
      return x;
    }
    public static void main (String [] args) 
    {
        Scanner inp = new Scanner(System.in); 
        System.out.println(start(inp.nextInt()));
    }
}

EvoSuite Arguments

Inferring from this example, when I compile and run this for the start function, it works and generates a test set: also works when I use target_method

java -Xmx1G  -Xss1G  -jar evosuite-1.2.0.jar  -projectCP ./  -class EvoDriver  -seed 110   -Dsearch\_budget=60  -Dstopping\_condition=MaxTime  -Dtarget\_method=start(I)I 

But I don't know how to make this work for other types of input parameters (or set of input parameters).

Current Result

For example, once it failed for deep1 function and in the report it used deep1(z)z. But when I try this (or deep1(b)b), it fails.

* EvoSuite 1.2.0
* Going to generate test cases for class: EvoDriver
* Starting Client-0
* Connecting to master process on port 14647
* Analyzing classpath: 
  - ./
* Finished analyzing classpath
* Generating tests for class EvoDriver
* Test criteria:
  - Line Coverage
  - Branch Coverage
  - Exception
  - Mutation testing (weak)
  - Method-Output Coverage
  - Top-Level Method Coverage
  - No-Exception Top-Level Method Coverage
  - Context Branch Coverage
* Total number of test goals for DYNAMOSA: 22
* Using seed 124
* Starting evolution
[Progress:>                             0%] [Cov:>                                  0%]* Computation finished
[MASTER] 15:45:35.276 [logback-2] ERROR ClientNodeImpl - Error when generating tests for: EvoDriver with seed 124. Configuration id : null
java.lang.NullPointerException: null
    at org.evosuite.ga.metaheuristics.mosa.structural.MultiCriteriaManager.addDependencies4WeakMutation(MultiCriteriaManager.java:298)
    at org.evosuite.ga.metaheuristics.mosa.structural.MultiCriteriaManager.<init>(MultiCriteriaManager.java:121)
    at org.evosuite.ga.metaheuristics.mosa.DynaMOSA.generateSolution(DynaMOSA.java:146)
    at org.evosuite.ga.metaheuristics.TestSuiteAdapter.generateSolution(TestSuiteAdapter.java:136)
    at org.evosuite.strategy.MOSuiteStrategy.generateTests(MOSuiteStrategy.java:122)
    at org.evosuite.TestSuiteGenerator.generateTests(TestSuiteGenerator.java:630)

Expected result

Can you please provide more information on the use of this option?