Skip to content

Generate standard tests for symbolic executions with mocking in parametrized mode #1252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.MethodId
import org.utbot.framework.plugin.api.UtExecutionSuccess
import org.utbot.framework.plugin.api.UtMethodTestSet
import org.utbot.framework.plugin.api.UtSymbolicExecution
import org.utbot.framework.plugin.api.util.description
import org.utbot.framework.plugin.api.util.humanReadableName
import org.utbot.fuzzer.UtFuzzedExecution
Expand Down Expand Up @@ -211,18 +212,35 @@ internal class CgTestClassConstructor(val context: CgContext) :
)
}

regions += CgSimpleRegion(
"Tests for method ${methodUnderTest.humanReadableName} that cannot be presented as parameterized",
collectAdditionalTestsForParameterizedMode(testSet),
)
}

private fun collectAdditionalTestsForParameterizedMode(testSet: CgMethodTestSet): List<CgTestMethod> {
val (methodUnderTest, _, _, _) = testSet
val testCaseTestMethods = mutableListOf<CgTestMethod>()

// We cannot track mocking in fuzzed executions,
// so we generate standard tests for each [UtFuzzedExecution].
// [https://github.com/UnitTestBot/UTBotJava/issues/1137]
val testCaseTestMethods = mutableListOf<CgTestMethod>()
for (execution in testSet.executions.filterIsInstance<UtFuzzedExecution>()) {
testCaseTestMethods += methodConstructor.createTestMethod(methodUnderTest, execution)
}
testSet.executions
.filterIsInstance<UtFuzzedExecution>()
.forEach { execution ->
testCaseTestMethods += methodConstructor.createTestMethod(methodUnderTest, execution)
}

regions += CgSimpleRegion(
"FUZZER: EXECUTIONS for method ${methodUnderTest.humanReadableName}",
testCaseTestMethods,
)
// Also, we generate standard tests for symbolic executions with force mocking.
// [https://github.com/UnitTestBot/UTBotJava/issues/1231]
testSet.executions
.filterIsInstance<UtSymbolicExecution>()
.filter { it.containsMocking }
.forEach { execution ->
testCaseTestMethods += methodConstructor.createTestMethod(methodUnderTest, execution)
}

return testCaseTestMethods
}

/**
Expand Down