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

Loss of determinism in Evosuite behavior #397

Open pietrobraione opened 2 years ago

pietrobraione commented 2 years ago

When fed by the same random seed Evosuite produces, in some situations, different results. I have experienced this loss in determinism since version 1.1.1 with a modified version of Evosuite that we are using for our test generator TARDIS, but the issue can be tracked to the unmodified Evosuite source code. I detected a source of nondeterminism in the use of the Collectors.toSet() method to gather the assignable classes from a test cluster in the code of the Set<Class<?>> ClassCastManager.getAssignableClassesFromTestCluster(Predicate<Class<?>>) method:

https://github.com/EvoSuite/evosuite/blob/8730aedd6cbcbeac1d7f246b4f223bda395212c9/client/src/main/java/org/evosuite/seeding/CastClassManager.java#L325

The Collectors.toSet() collector is unordered, as reported in the documentation: Because of this, the instantiation of the generic parameters during the creation of a test may picks different concrete classes under different runs of Evosuite with same random seed. I suggest to fix this issue by replacing line 325 with

.collect(Collectors.toCollection(LinkedHashSet::new));

assuming that the source of the stream is deterministically ordered.