@@ -26,7 +26,9 @@ import org.utbot.framework.codegen.model.visitor.importUtilMethodDependencies
2626import org.utbot.framework.plugin.api.CgMethodTestSet
2727import org.utbot.framework.plugin.api.ExecutableId
2828import org.utbot.framework.plugin.api.MethodId
29+ import org.utbot.framework.plugin.api.UtExecutionSuccess
2930import org.utbot.framework.plugin.api.UtMethodTestSet
31+ import org.utbot.framework.plugin.api.substituteExecutions
3032import org.utbot.framework.plugin.api.util.description
3133import org.utbot.framework.plugin.api.util.kClass
3234import kotlin.reflect.KClass
@@ -107,22 +109,29 @@ internal class CgTestClassConstructor(val context: CgContext) :
107109 }
108110 }
109111 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,
124122 )
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+ }
126135 }
127136 }
128137
@@ -141,6 +150,30 @@ internal class CgTestClassConstructor(val context: CgContext) :
141150 .merge(failure.description, 1 , Int ::plus)
142151 }
143152
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+
144177 // TODO: collect imports of util methods
145178 private fun createUtilMethods (): List <CgUtilMethod > {
146179 val utilMethods = mutableListOf<CgUtilMethod >()
0 commit comments