EvoSuite / evosuite

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

run generated tests on jacoco with '-Duse_separate_classloader=false',but mock env failed #427

Open SRWFan opened 2 years ago

SRWFan commented 2 years ago

I'm using evosuite generating tests with param '-Duse_separate_classloader=false',it works on jacoco covorage tool.But in some cases,which it needed some mock environment likes current time or randoms,it failed the tests. I've read the source code and found that if previous test run without evorunner,the class would load without evosuite instrument.

if (!active || !RuntimeInstrumentation.checkIfCanInstrument(classWithDots) || classWithDots.startsWith(PackageInfo.getEvoSuitePackage())) {
    return classfileBuffer;
}

Then the generated test cases run,but the class would not instrument since it has been loaded,which makes the mocks disabled. I've found some code in classes initializing,it seems like to resolve this problem,can it really works?

        //retransformIfNeeded(classes); // cannot do it, as retransformation does not really work :(
reply2techie commented 1 year ago

Hi, I am trying to use Evouite and integrating the jacoco code coverage using Gradle. Did you try the offline code coverage? Do you recommend using the 'use_separate_classloader=false' instead?