Open alisevych opened 1 year ago
Additional context
Without changes from PR - #1265 - the reflection in test class is a bit different. But too much reflection is also present.
Following tests are generated with this build
With same settings - Symbolic execution only (100%) and Mock everything outside package
///region Test suites for executable org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable
///region
@Test
public void testTestTreeSetWithComparable1() {
CollectionExample collectionExample = new CollectionExample();
/* This test fails because method [org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable] produces [java.lang.NullPointerException]
org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable(CollectionExample.java:124) */
collectionExample.testTreeSetWithComparable(null);
}
@Test
public void testTestTreeSetWithComparable2() throws Exception {
CollectionExample collectionExample = new CollectionExample();
ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", null);
setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);
boolean actual = collectionExample.testTreeSetWithComparable(set);
assertFalse(actual);
}
@Test
public void testTestTreeSetWithComparable3() throws Exception {
CollectionExample collectionExample = new CollectionExample();
ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
Object index = createInstance("java.util.concurrent.ConcurrentSkipListMap$Index");
Object node = createInstance("java.util.concurrent.ConcurrentSkipListMap$Node");
setField(index, "java.util.concurrent.ConcurrentSkipListMap$Index", "node", node);
setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", index);
LongAdder longAdder = ((LongAdder) createInstance("java.util.concurrent.atomic.LongAdder"));
Object[] cellArray = createArray("java.util.concurrent.atomic.Striped64$Cell", 0);
setField(longAdder, "java.util.concurrent.atomic.Striped64", "cells", cellArray);
setField(longAdder, "java.util.concurrent.atomic.Striped64", "base", 2147483647L);
setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "adder", longAdder);
setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);
boolean actual = collectionExample.testTreeSetWithComparable(set);
assertTrue(actual);
}
///endregion
///endregion
///region Test suites for executable org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable
///region
@Test
public void testTestTreeSetWithoutComparable1() {
CollectionExample collectionExample = new CollectionExample();
/* This test fails because method [org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable] produces [java.lang.NullPointerException]
org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable(CollectionExample.java:114) */
collectionExample.testTreeSetWithoutComparable(null);
}
@Test
public void testTestTreeSetWithoutComparable2() throws Exception {
CollectionExample collectionExample = new CollectionExample();
ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", null);
setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);
boolean actual = collectionExample.testTreeSetWithoutComparable(set);
assertFalse(actual);
}
@Test
public void testTestTreeSetWithoutComparable3() throws Exception {
CollectionExample collectionExample = new CollectionExample();
ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
Object index = createInstance("java.util.concurrent.ConcurrentSkipListMap$Index");
Object node = createInstance("java.util.concurrent.ConcurrentSkipListMap$Node");
setField(index, "java.util.concurrent.ConcurrentSkipListMap$Index", "node", node);
setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", index);
LongAdder longAdder = ((LongAdder) createInstance("java.util.concurrent.atomic.LongAdder"));
Object[] cellArray = createArray("java.util.concurrent.atomic.Striped64$Cell", 0);
setField(longAdder, "java.util.concurrent.atomic.Striped64", "cells", cellArray);
setField(longAdder, "java.util.concurrent.atomic.Striped64", "base", 2147483647L);
setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "adder", longAdder);
setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);
boolean actual = collectionExample.testTreeSetWithoutComparable(set);
assertTrue(actual);
}
///endregion
///endregion
The reason for it -- we don't have a wrapper for TreeSet
, NavigableSet
and OrderedSet
, and the right way to fix it -- create such wrappers. It is definitely a problem, but I think we are unable to fix it before the nearest release
Description
Symbolic execution for examples using TreeSet produces tests with too complex reflection with system classes.
To Reproduce
Mock everything outside package
Expected behavior
Generated tests are supposed to instantiate objects regularly.
Actual behavior
Generated tests contain too much reflection with system classes
Visual proofs (screenshots, logs, images)
Environment
Windows 10 Pro IntelliJ IDEA 2022.1.4 (JBR 11) UTBotJava project (Gradle , JDK 11)
Additional context
Code taken from PR - #988