@@ -37,7 +37,6 @@ import org.utbot.framework.codegen.model.tree.buildTestClassBody
37
37
import org.utbot.framework.codegen.model.tree.buildTestClassFile
38
38
import org.utbot.framework.codegen.model.visitor.importUtilMethodDependencies
39
39
import org.utbot.framework.plugin.api.ClassId
40
- import org.utbot.framework.plugin.api.ExecutableId
41
40
import org.utbot.framework.plugin.api.MethodId
42
41
import org.utbot.framework.plugin.api.UtExecutionSuccess
43
42
import org.utbot.framework.plugin.api.UtMethodTestSet
@@ -140,45 +139,18 @@ internal class CgTestClassConstructor(val context: CgContext) :
140
139
.filter { it.result is UtExecutionSuccess }
141
140
.map { (it.result as UtExecutionSuccess ).model }
142
141
143
- val (methodUnderTest, _, _, clustersInfo) = testSet
144
142
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)
162
143
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
+ )
180
152
}
181
- }
153
+ }.onFailure { e -> processFailure(testSet, e) }
182
154
183
155
val errors = testSet.allErrors
184
156
if (errors.isNotEmpty()) {
@@ -195,29 +167,61 @@ internal class CgTestClassConstructor(val context: CgContext) :
195
167
.merge(failure.description, 1 , Int ::plus)
196
168
}
197
169
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
+
198
192
private fun createParametrizedTestAndDataProvider (
199
193
testSet : CgMethodTestSet ,
200
- requiredFields : MutableList <CgParameterDeclaration >,
201
- regions : MutableList <CgRegion <CgMethod >>,
202
- methodUnderTest : ExecutableId ,
194
+ regions : MutableList <CgRegion <CgMethod >>
203
195
) {
204
- runCatching {
205
- val dataProviderMethodName = nameGenerator.dataProviderMethodNameFor(testSet.executableId)
196
+ val (methodUnderTest, _, _, _) = testSet
206
197
207
- val parameterizedTestMethod =
208
- methodConstructor.createParameterizedTestMethod(testSet, dataProviderMethodName )
198
+ for (preparedTestSet in testSet.prepareForParameterizedTestGeneration()) {
199
+ val dataProviderMethodName = nameGenerator.dataProviderMethodNameFor(preparedTestSet.executableId )
209
200
210
- requiredFields + = parameterizedTestMethod.requiredFields
201
+ val parameterizedTestMethod =
202
+ methodConstructor.createParameterizedTestMethod(preparedTestSet, dataProviderMethodName)
211
203
212
204
testFrameworkManager.addDataProvider(
213
- methodConstructor.createParameterizedTestDataProvider(testSet , dataProviderMethodName)
205
+ methodConstructor.createParameterizedTestDataProvider(preparedTestSet , dataProviderMethodName)
214
206
)
215
207
216
208
regions + = CgSimpleRegion (
217
209
" Parameterized test for method ${methodUnderTest.humanReadableName} " ,
218
210
listOf (parameterizedTestMethod),
219
211
)
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
+ )
221
225
}
222
226
223
227
/* *
0 commit comments