@@ -26,7 +26,9 @@ import org.utbot.framework.codegen.model.visitor.importUtilMethodDependencies
26
26
import org.utbot.framework.plugin.api.CgMethodTestSet
27
27
import org.utbot.framework.plugin.api.ExecutableId
28
28
import org.utbot.framework.plugin.api.MethodId
29
+ import org.utbot.framework.plugin.api.UtExecutionSuccess
29
30
import org.utbot.framework.plugin.api.UtMethodTestSet
31
+ import org.utbot.framework.plugin.api.substituteExecutions
30
32
import org.utbot.framework.plugin.api.util.description
31
33
import org.utbot.framework.plugin.api.util.kClass
32
34
import kotlin.reflect.KClass
@@ -107,22 +109,29 @@ internal class CgTestClassConstructor(val context: CgContext) :
107
109
}
108
110
}
109
111
ParametrizedTestSource .PARAMETRIZE -> {
110
- runCatching {
111
- val dataProviderMethodName = nameGenerator.dataProviderMethodNameFor(testSet.executableId)
112
-
113
- val parameterizedTestMethod =
114
- methodConstructor.createParameterizedTestMethod(testSet, dataProviderMethodName)
115
-
116
- requiredFields + = parameterizedTestMethod.requiredFields
117
-
118
- cgDataProviderMethods + =
119
- methodConstructor.createParameterizedTestDataProvider(testSet, dataProviderMethodName)
120
-
121
- regions + = CgSimpleRegion (
122
- " Parameterized test for method ${methodUnderTest.displayName} " ,
123
- listOf (parameterizedTestMethod),
112
+ val groupedExecutions = executions
113
+ .filter { it.result is UtExecutionSuccess }
114
+ .groupBy { (it.result as UtExecutionSuccess ).model.classId }
115
+
116
+ if (groupedExecutions.isEmpty()) {
117
+ processParametrizedTestSet(
118
+ testSet,
119
+ requiredFields,
120
+ regions,
121
+ methodUnderTest,
124
122
)
125
- }.onFailure { error -> processFailure(testSet, error) }
123
+ } else {
124
+ for (executionsGroup in groupedExecutions.values) {
125
+ val testSet = testSet.substituteExecutions(executionsGroup)
126
+
127
+ processParametrizedTestSet(
128
+ testSet,
129
+ requiredFields,
130
+ regions,
131
+ methodUnderTest,
132
+ )
133
+ }
134
+ }
126
135
}
127
136
}
128
137
@@ -141,6 +150,30 @@ internal class CgTestClassConstructor(val context: CgContext) :
141
150
.merge(failure.description, 1 , Int ::plus)
142
151
}
143
152
153
+ private fun processParametrizedTestSet (
154
+ testSet : CgMethodTestSet ,
155
+ requiredFields : MutableList <CgParameterDeclaration >,
156
+ regions : MutableList <CgRegion <CgMethod >>,
157
+ methodUnderTest : ExecutableId ,
158
+ ) {
159
+ runCatching {
160
+ val dataProviderMethodName = nameGenerator.dataProviderMethodNameFor(testSet.executableId)
161
+
162
+ val parameterizedTestMethod =
163
+ methodConstructor.createParameterizedTestMethod(testSet, dataProviderMethodName)
164
+
165
+ requiredFields + = parameterizedTestMethod.requiredFields
166
+
167
+ cgDataProviderMethods + =
168
+ methodConstructor.createParameterizedTestDataProvider(testSet, dataProviderMethodName)
169
+
170
+ regions + = CgSimpleRegion (
171
+ " Parameterized test for method ${methodUnderTest.displayName} " ,
172
+ listOf (parameterizedTestMethod),
173
+ )
174
+ }.onFailure { error -> processFailure(testSet, error) }
175
+ }
176
+
144
177
// TODO: collect imports of util methods
145
178
private fun createUtilMethods (): List <CgUtilMethod > {
146
179
val utilMethods = mutableListOf<CgUtilMethod >()
0 commit comments