Skip to content

Improve documentation for regions in parametrized tests #1340

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 2 commits into from
Nov 11, 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 @@ -110,7 +110,11 @@ internal class CgTestClassConstructor(val context: CgContext) :

val currentTestClassDataProviderMethods = currentTestClassContext.cgDataProviderMethods
if (currentTestClassDataProviderMethods.isNotEmpty()) {
staticDeclarationRegions += CgStaticsRegion("Data providers", currentTestClassDataProviderMethods)
staticDeclarationRegions +=
CgStaticsRegion(
"Data provider methods for parametrized tests",
currentTestClassDataProviderMethods,
)
}

if (currentTestClass == outerMostTestClass) {
Expand Down Expand Up @@ -228,34 +232,47 @@ internal class CgTestClassConstructor(val context: CgContext) :
}

regions += CgSimpleRegion(
"Tests for method ${methodUnderTest.humanReadableName} that cannot be presented as parameterized",
collectAdditionalTestsForParameterizedMode(testSet),
"SYMBOLIC EXECUTION: additional tests for symbolic executions for method ${methodUnderTest.humanReadableName}",
collectAdditionalSymbolicTestsForParametrizedMode(testSet),
)

regions += CgSimpleRegion(
"FUZZER: Tests for method ${methodUnderTest.humanReadableName}",
collectFuzzerTestsForParameterizedMode(testSet),
)
}

private fun collectAdditionalTestsForParameterizedMode(testSet: CgMethodTestSet): List<CgTestMethod> {
val (methodUnderTest, _, _, _) = testSet
val testCaseTestMethods = mutableListOf<CgTestMethod>()
/**
* Collects standard tests for fuzzer executions in parametrized mode.
* This is a requirement from [https://github.com/UnitTestBot/UTBotJava/issues/1137].
*/
private fun collectFuzzerTestsForParameterizedMode(testSet: CgMethodTestSet): List<CgTestMethod> {
val testMethods = mutableListOf<CgTestMethod>()

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

// Also, we generate standard tests for symbolic executions with force mocking.
// [https://github.com/UnitTestBot/UTBotJava/issues/1231]
return testMethods
}

/**
* Collects standard tests for symbolic executions that can't be included into parametrized tests.
* This is a requirement from [https://github.com/UnitTestBot/UTBotJava/issues/1231].
*/
private fun collectAdditionalSymbolicTestsForParametrizedMode(testSet: CgMethodTestSet): List<CgTestMethod> {
val testMethods = mutableListOf<CgTestMethod>()

testSet.executions
.filterIsInstance<UtSymbolicExecution>()
.filter { it.containsMocking }
.forEach { execution ->
testCaseTestMethods += methodConstructor.createTestMethod(methodUnderTest, execution)
testMethods += methodConstructor.createTestMethod(testSet.executableId, execution)
}

return testCaseTestMethods
return testMethods
}

/**
Expand Down