@@ -17,16 +17,19 @@ import org.utbot.framework.codegen.domain.models.CgTestMethodCluster
17
17
import org.utbot.framework.codegen.domain.models.CgTripleSlashMultilineComment
18
18
import org.utbot.framework.codegen.domain.models.CgUtilEntity
19
19
import org.utbot.framework.codegen.domain.models.CgUtilMethod
20
- import org.utbot.framework.codegen.domain.models.SimpleTestClassModel
21
20
import org.utbot.framework.codegen.domain.models.TestClassModel
22
21
import org.utbot.framework.codegen.renderer.importUtilMethodDependencies
23
22
import org.utbot.framework.codegen.reports.TestsGenerationReport
24
23
import org.utbot.framework.codegen.services.CgNameGenerator
25
24
import org.utbot.framework.codegen.services.framework.TestFrameworkManager
26
25
import org.utbot.framework.plugin.api.ClassId
27
26
import org.utbot.framework.plugin.api.MethodId
27
+ import org.utbot.framework.plugin.api.UtExecution
28
+ import org.utbot.framework.plugin.api.UtExecutionFailure
29
+ import org.utbot.framework.plugin.api.UtExecutionSuccess
28
30
import org.utbot.framework.plugin.api.UtMethodTestSet
29
31
import org.utbot.framework.plugin.api.util.description
32
+ import org.utbot.framework.util.calculateSize
30
33
31
34
abstract class CgAbstractTestClassConstructor <T : TestClassModel >(val context : CgContext ):
32
35
CgContextOwner by context,
@@ -91,6 +94,12 @@ abstract class CgAbstractTestClassConstructor<T : TestClassModel>(val context: C
91
94
) {
92
95
val (_, _, clustersInfo) = testSet
93
96
97
+ // `stateAfter` is not accounted here, because usually most of it is not rendered
98
+ val executionToSizeCache = testSet.executions.associateWith { execution ->
99
+ execution.stateBefore.calculateSize() +
100
+ ((execution.result as ? UtExecutionSuccess )?.model?.calculateSize() ? : 1 )
101
+ }
102
+
94
103
for ((clusterSummary, executionIndices) in clustersInfo) {
95
104
val currentTestCaseTestMethods = mutableListOf<CgTestMethod >()
96
105
emptyLineIfNeeded()
@@ -100,11 +109,23 @@ abstract class CgAbstractTestClassConstructor<T : TestClassModel>(val context: C
100
109
executionIndices to false
101
110
}
102
111
103
- for (i in checkedRange) {
104
- withExecutionIdScope(i) {
105
- currentTestCaseTestMethods + = methodConstructor.createTestMethod(testSet, testSet.executions[i])
112
+ testSet.executions
113
+ .withIndex()
114
+ .toList()
115
+ .slice(checkedRange)
116
+ .sortedWith(
117
+ // NPE tests are rendered last, because oftentimes they are meaningless in a sense
118
+ // that they pass `null` somewhere where `null` is never passed in production
119
+ compareBy<IndexedValue <UtExecution >> { (_, execution) ->
120
+ if ((execution.result as ? UtExecutionFailure )?.exception is NullPointerException ) 1 else - 1
121
+ }
122
+ // we place "smaller" tests earlier, since they are easier to read
123
+ .thenComparingInt { (_, execution) -> executionToSizeCache.getValue(execution) }
124
+ ).forEach { (i, execution) ->
125
+ withExecutionIdScope(i) {
126
+ currentTestCaseTestMethods + = methodConstructor.createTestMethod(testSet, execution)
127
+ }
106
128
}
107
- }
108
129
109
130
val comments = listOf (" Actual number of generated tests (${executionIndices.last - executionIndices.first} ) exceeds per-method limit (${UtSettings .maxTestsPerMethodInRegion} )" ,
110
131
" The limit can be configured in '{HOME_DIR}/.utbot/settings.properties' with 'maxTestsPerMethod' property" )
0 commit comments