@@ -37,7 +37,6 @@ import org.utbot.framework.codegen.model.tree.buildTestClassBody
3737import org.utbot.framework.codegen.model.tree.buildTestClassFile
3838import org.utbot.framework.codegen.model.visitor.importUtilMethodDependencies
3939import org.utbot.framework.plugin.api.ClassId
40- import org.utbot.framework.plugin.api.ExecutableId
4140import org.utbot.framework.plugin.api.MethodId
4241import org.utbot.framework.plugin.api.UtExecutionSuccess
4342import org.utbot.framework.plugin.api.UtMethodTestSet
@@ -140,45 +139,18 @@ internal class CgTestClassConstructor(val context: CgContext) :
140139 .filter { it.result is UtExecutionSuccess }
141140 .map { (it.result as UtExecutionSuccess ).model }
142141
143- val (methodUnderTest, _, _, clustersInfo) = testSet
144142 val regions = mutableListOf<CgRegion <CgMethod >>()
145- val requiredFields = mutableListOf<CgParameterDeclaration >()
146-
147- when (context.parametrizedTestSource) {
148- ParametrizedTestSource .DO_NOT_PARAMETRIZE -> {
149- for ((clusterSummary, executionIndices) in clustersInfo) {
150- val currentTestCaseTestMethods = mutableListOf<CgTestMethod >()
151- emptyLineIfNeeded()
152- for (i in executionIndices) {
153- runCatching {
154- currentTestCaseTestMethods + = methodConstructor.createTestMethod(methodUnderTest, testSet.executions[i])
155- }.onFailure { e -> processFailure(testSet, e) }
156- }
157- val clusterHeader = clusterSummary?.header
158- val clusterContent = clusterSummary?.content
159- ?.split(' \n ' )
160- ?.let { CgTripleSlashMultilineComment (it) }
161- regions + = CgTestMethodCluster (clusterHeader, clusterContent, currentTestCaseTestMethods)
162143
163- testsGenerationReport.addTestsByType(testSet, currentTestCaseTestMethods)
164- }
165- }
166- ParametrizedTestSource .PARAMETRIZE -> {
167- // Mocks are not supported in parametrized tests, we should exclude them
168- val testSetWithoutMocking = testSet.excludeExecutionsWithMocking()
169-
170- for (splitByExecutionTestSet in testSetWithoutMocking.splitExecutionsByResult()) {
171- for (splitByChangedStaticsTestSet in splitByExecutionTestSet.splitExecutionsByChangedStatics()) {
172- createParametrizedTestAndDataProvider(
173- splitByChangedStaticsTestSet,
174- requiredFields,
175- regions,
176- methodUnderTest
177- )
178- }
179- }
144+ runCatching {
145+ when (context.parametrizedTestSource) {
146+ ParametrizedTestSource .DO_NOT_PARAMETRIZE -> createTest(testSet, regions)
147+ ParametrizedTestSource .PARAMETRIZE ->
148+ createParametrizedTestAndDataProvider(
149+ testSet,
150+ regions
151+ )
180152 }
181- }
153+ }.onFailure { e -> processFailure(testSet, e) }
182154
183155 val errors = testSet.allErrors
184156 if (errors.isNotEmpty()) {
@@ -195,29 +167,61 @@ internal class CgTestClassConstructor(val context: CgContext) :
195167 .merge(failure.description, 1 , Int ::plus)
196168 }
197169
170+ private fun createTest (
171+ testSet : CgMethodTestSet ,
172+ regions : MutableList <CgRegion <CgMethod >>
173+ ) {
174+ val (methodUnderTest, _, _, clustersInfo) = testSet
175+
176+ for ((clusterSummary, executionIndices) in clustersInfo) {
177+ val currentTestCaseTestMethods = mutableListOf<CgTestMethod >()
178+ emptyLineIfNeeded()
179+ for (i in executionIndices) {
180+ currentTestCaseTestMethods + = methodConstructor.createTestMethod(methodUnderTest, testSet.executions[i])
181+ }
182+ val clusterHeader = clusterSummary?.header
183+ val clusterContent = clusterSummary?.content
184+ ?.split(' \n ' )
185+ ?.let { CgTripleSlashMultilineComment (it) }
186+ regions + = CgTestMethodCluster (clusterHeader, clusterContent, currentTestCaseTestMethods)
187+
188+ testsGenerationReport.addTestsByType(testSet, currentTestCaseTestMethods)
189+ }
190+ }
191+
198192 private fun createParametrizedTestAndDataProvider (
199193 testSet : CgMethodTestSet ,
200- requiredFields : MutableList <CgParameterDeclaration >,
201- regions : MutableList <CgRegion <CgMethod >>,
202- methodUnderTest : ExecutableId ,
194+ regions : MutableList <CgRegion <CgMethod >>
203195 ) {
204- runCatching {
205- val dataProviderMethodName = nameGenerator.dataProviderMethodNameFor(testSet.executableId)
196+ val (methodUnderTest, _, _, _) = testSet
206197
207- val parameterizedTestMethod =
208- methodConstructor.createParameterizedTestMethod(testSet, dataProviderMethodName )
198+ for (preparedTestSet in testSet.prepareForParameterizedTestGeneration()) {
199+ val dataProviderMethodName = nameGenerator.dataProviderMethodNameFor(preparedTestSet.executableId )
209200
210- requiredFields + = parameterizedTestMethod.requiredFields
201+ val parameterizedTestMethod =
202+ methodConstructor.createParameterizedTestMethod(preparedTestSet, dataProviderMethodName)
211203
212204 testFrameworkManager.addDataProvider(
213- methodConstructor.createParameterizedTestDataProvider(testSet , dataProviderMethodName)
205+ methodConstructor.createParameterizedTestDataProvider(preparedTestSet , dataProviderMethodName)
214206 )
215207
216208 regions + = CgSimpleRegion (
217209 " Parameterized test for method ${methodUnderTest.humanReadableName} " ,
218210 listOf (parameterizedTestMethod),
219211 )
220- }.onFailure { error -> processFailure(testSet, error) }
212+ }
213+
214+ // We cannot track mocking in fuzzed executions, so we generate standard tests for them
215+ // [https://github.com/UnitTestBot/UTBotJava/issues/1137]
216+ val testCaseTestMethods = mutableListOf<CgTestMethod >()
217+ for (execution in testSet.prepareFuzzedExecutions().executions) {
218+ testCaseTestMethods + = methodConstructor.createTestMethod(methodUnderTest, execution)
219+ }
220+
221+ regions + = CgSimpleRegion (
222+ " FUZZER: EXECUTIONS for method ${methodUnderTest.humanReadableName} " ,
223+ testCaseTestMethods,
224+ )
221225 }
222226
223227 /* *
0 commit comments