diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt index 7c915bf600..d02e492510 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt @@ -61,6 +61,7 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.yield import org.utbot.framework.codegen.services.language.CgLanguageAssistant +import org.utbot.framework.minimization.minimizeExecutions import org.utbot.framework.plugin.api.util.isSynthetic internal const val junitVersion = 4 @@ -180,10 +181,7 @@ fun runGeneration( runFromEstimator: Boolean, methodNameFilter: String? = null // For debug purposes you can specify method name ): StatsForClass = runBlocking { - - - - val testSets: MutableList = mutableListOf() + val testsByMethod: MutableMap> = mutableMapOf() val currentContext = utContext val timeBudgetMs = timeLimitSec * 1000 @@ -340,8 +338,7 @@ fun runGeneration( } statsForClass.testedClassNames.add(className) - //TODO: it is a strange hack to create fake test case for one [UtResult] - testSets.add(UtMethodTestSet(method, listOf(result))) + testsByMethod.getOrPut(method) { mutableListOf() } += result } catch (e: Throwable) { //Here we need isolation logger.error(e) { "Code generation failed" } @@ -393,6 +390,8 @@ fun runGeneration( } cancellator.cancel() + val testSets = testsByMethod.map { (method, executions) -> UtMethodTestSet(method, minimizeExecutions(executions)) } + logger.info().bracket("Flushing tests for [${cut.simpleName}] on disk") { writeTestClass(cut, codeGenerator.generateAsString(testSets)) }