Skip to content

Commit fab8ed2

Browse files
Rename UtTestCase to UtMethodTestSet
1 parent b7bc926 commit fab8ed2

File tree

27 files changed

+228
-254
lines changed

27 files changed

+228
-254
lines changed

utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi
2828
import org.utbot.framework.plugin.api.TreatOverflowAsError
2929
import org.utbot.framework.plugin.api.TestCaseGenerator
3030
import org.utbot.framework.plugin.api.UtMethod
31-
import org.utbot.framework.plugin.api.UtTestCase
31+
import org.utbot.framework.plugin.api.UtMethodTestSet
3232
import org.utbot.summary.summarize
3333
import java.io.File
3434
import java.lang.reflect.Method
@@ -158,7 +158,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
158158
sourceCodeFile: Path? = null,
159159
searchDirectory: Path,
160160
chosenClassesToMockAlways: Set<ClassId>
161-
): List<UtTestCase> =
161+
): List<UtMethodTestSet> =
162162
TestCaseGenerator.generate(
163163
targetMethods,
164164
mockStrategy,
@@ -184,11 +184,11 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
184184
}
185185
}
186186

187-
protected fun generateTest(classUnderTest: KClass<*>, testClassname: String, testCases: List<UtTestCase>): String =
187+
protected fun generateTest(classUnderTest: KClass<*>, testClassname: String, testSets: List<UtMethodTestSet>): String =
188188
initializeCodeGenerator(
189189
testFramework,
190190
classUnderTest
191-
).generateAsString(testCases, testClassname)
191+
).generateAsString(testSets, testClassname)
192192

193193
protected fun initializeEngine(workingDirectory: Path) {
194194
val classPathNormalized =

utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsCommand.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.utbot.common.PathUtil.toPath
1111
import org.utbot.engine.Mocker
1212
import org.utbot.framework.plugin.api.ClassId
1313
import org.utbot.framework.plugin.api.CodegenLanguage
14-
import org.utbot.framework.plugin.api.UtTestCase
14+
import org.utbot.framework.plugin.api.UtMethodTestSet
1515
import org.utbot.framework.plugin.api.util.UtContext
1616
import org.utbot.framework.plugin.api.util.withUtContext
1717
import org.utbot.sarif.SarifReport
@@ -128,7 +128,7 @@ class GenerateTestsCommand :
128128
}
129129
}
130130

131-
private fun generateReport(classFqn: String, testCases: List<UtTestCase>, testClassBody: String) = try {
131+
private fun generateReport(classFqn: String, testSets: List<UtMethodTestSet>, testClassBody: String) = try {
132132
// reassignments for smart casts
133133
val testsFilePath = output
134134
val projectRootPath = projectRoot
@@ -143,7 +143,7 @@ class GenerateTestsCommand :
143143
else -> {
144144
val sourceFinding =
145145
SourceFindingStrategyDefault(classFqn, sourceCodeFile, testsFilePath, projectRootPath)
146-
val report = SarifReport(testCases, testClassBody, sourceFinding).createReport()
146+
val report = SarifReport(testSets, testClassBody, sourceFinding).createReport()
147147
saveToFile(report, sarifReport)
148148
println("The report was saved to \"$sarifReport\". You can open it using the VS Code extension \"Sarif Viewer\".")
149149
}

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,13 @@ data class UtMethod<R>(
9090
}
9191
}
9292

93-
/**
94-
* Test case.
95-
*
96-
* Note: it should not be transformed into data class since it is used as a key in maps.
97-
* The clusters in it are mutable objects, therefore, we might have problems with hash because of it.
98-
*/
99-
@Suppress("unused")
100-
class UtTestCase(
93+
data class UtMethodTestSet(
10194
val method: UtMethod<*>,
10295
val executions: List<UtExecution> = emptyList(),
10396
val jimpleBody: JimpleBody? = null,
10497
val errors: Map<String, Int> = emptyMap(),
105-
private val clustersInfo: List<Pair<UtClusterInfo?, IntRange>> = listOf(null to executions.indices)
106-
) {
107-
operator fun component1() = method
108-
operator fun component2() = executions
109-
operator fun component3() = jimpleBody
110-
operator fun component4() = errors
111-
operator fun component5() = clustersInfo
112-
113-
fun copy(
114-
method: UtMethod<*> = this.method,
115-
executions: List<UtExecution> = this.executions,
116-
jimpleBody: JimpleBody? = this.jimpleBody,
117-
errors: Map<String, Int> = this.errors,
118-
clustersInfo: List<Pair<UtClusterInfo?, IntRange>> = this.clustersInfo
119-
) = UtTestCase(method, executions, jimpleBody, errors, clustersInfo)
120-
}
98+
val clustersInfo: List<Pair<UtClusterInfo?, IntRange>> = listOf(null to executions.indices)
99+
)
121100

122101
data class Step(
123102
val stmt: Stmt,

utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.utbot.framework.plugin.api.TestCaseGenerator
2020
import org.utbot.framework.plugin.api.UtExecution
2121
import org.utbot.framework.plugin.api.UtMethod
2222
import org.utbot.framework.plugin.api.UtPrimitiveModel
23-
import org.utbot.framework.plugin.api.UtTestCase
23+
import org.utbot.framework.plugin.api.UtMethodTestSet
2424
import org.utbot.framework.plugin.api.util.UtContext
2525
import org.utbot.framework.plugin.api.util.id
2626
import org.utbot.framework.plugin.api.util.isPrimitive
@@ -50,7 +50,7 @@ object UtBotJavaApi {
5050
@JvmOverloads
5151
fun generate(
5252
methodsForGeneration: List<TestMethodInfo>,
53-
generatedTestCases: List<UtTestCase> = mutableListOf(),
53+
generatedTestCases: List<UtMethodTestSet> = mutableListOf(),
5454
destinationClassName: String,
5555
classpath: String,
5656
dependencyClassPath: String,
@@ -66,15 +66,15 @@ object UtBotJavaApi {
6666

6767
val utContext = UtContext(classUnderTest.classLoader)
6868

69-
val testCases: MutableList<UtTestCase> = generatedTestCases.toMutableList()
69+
val testSets: MutableList<UtMethodTestSet> = generatedTestCases.toMutableList()
7070

7171
val concreteExecutor = ConcreteExecutor(
7272
UtExecutionInstrumentation,
7373
classpath,
7474
dependencyClassPath
7575
)
7676

77-
testCases.addAll(generateUnitTests(concreteExecutor, methodsForGeneration, classUnderTest))
77+
testSets.addAll(generateUnitTests(concreteExecutor, methodsForGeneration, classUnderTest))
7878

7979
if (stopConcreteExecutorOnExit) {
8080
concreteExecutor.close()
@@ -95,7 +95,7 @@ object UtBotJavaApi {
9595
}
9696

9797
testGenerator.generateAsString(
98-
testCases,
98+
testSets,
9999
destinationClassName
100100
)
101101
}
@@ -115,12 +115,12 @@ object UtBotJavaApi {
115115
dependencyClassPath: String,
116116
mockStrategyApi: MockStrategyApi = MockStrategyApi.OTHER_PACKAGES,
117117
generationTimeoutInMillis: Long = UtSettings.utBotGenerationTimeoutInMillis
118-
): MutableList<UtTestCase> {
118+
): MutableList<UtMethodTestSet> {
119119

120120
val utContext = UtContext(classUnderTest.classLoader)
121-
val testCases: MutableList<UtTestCase> = mutableListOf()
121+
val testSets: MutableList<UtMethodTestSet> = mutableListOf()
122122

123-
testCases.addAll(withUtContext(utContext) {
123+
testSets.addAll(withUtContext(utContext) {
124124
TestCaseGenerator
125125
.apply {
126126
init(
@@ -140,7 +140,7 @@ object UtBotJavaApi {
140140
)
141141
})
142142

143-
return testCases
143+
return testSets
144144
}
145145

146146
/**
@@ -158,7 +158,7 @@ object UtBotJavaApi {
158158
mockStrategyApi: MockStrategyApi = MockStrategyApi.OTHER_PACKAGES,
159159
generationTimeoutInMillis: Long = UtSettings.utBotGenerationTimeoutInMillis,
160160
primitiveValuesSupplier: CustomFuzzerValueSupplier = CustomFuzzerValueSupplier { null }
161-
): MutableList<UtTestCase> {
161+
): MutableList<UtMethodTestSet> {
162162
fun createPrimitiveModels(supplier: CustomFuzzerValueSupplier, classId: ClassId): Sequence<UtPrimitiveModel> =
163163
supplier
164164
.takeIf { classId.isPrimitive || classId.isPrimitiveWrapper || classId == stringClassId }
@@ -259,7 +259,7 @@ object UtBotJavaApi {
259259

260260
val utMethod = UtMethod(methodCallable, containingClass.kotlin)
261261

262-
UtTestCase(
262+
UtMethodTestSet(
263263
utMethod,
264264
listOf(utExecution)
265265
)

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.utbot.framework.codegen.model.visitor.CgAbstractRenderer
1515
import org.utbot.framework.plugin.api.CodegenLanguage
1616
import org.utbot.framework.plugin.api.MockFramework
1717
import org.utbot.framework.plugin.api.UtMethod
18-
import org.utbot.framework.plugin.api.UtTestCase
18+
import org.utbot.framework.plugin.api.UtMethodTestSet
1919
import org.utbot.framework.plugin.api.util.id
2020

2121
class CodeGenerator {
@@ -56,17 +56,17 @@ class CodeGenerator {
5656
}
5757

5858
//TODO: we support custom test class name only in utbot-online, probably support them in plugin as well
59-
fun generateAsString(testCases: Collection<UtTestCase>, testClassCustomName: String? = null): String =
60-
generateAsStringWithTestReport(testCases, testClassCustomName).generatedCode
59+
fun generateAsString(testSets: Collection<UtMethodTestSet>, testClassCustomName: String? = null): String =
60+
generateAsStringWithTestReport(testSets, testClassCustomName).generatedCode
6161

6262
//TODO: we support custom test class name only in utbot-online, probably support them in plugin as well
6363
fun generateAsStringWithTestReport(
64-
testCases: Collection<UtTestCase>,
64+
testSets: Collection<UtMethodTestSet>,
6565
testClassCustomName: String? = null,
6666
): TestsCodeWithTestReport =
6767
withCustomContext(testClassCustomName) {
6868
context.withClassScope {
69-
val testClassFile = CgTestClassConstructor(context).construct(testCases)
69+
val testClassFile = CgTestClassConstructor(context).construct(testSets)
7070
TestsCodeWithTestReport(renderClassFile(testClassFile), testClassFile.testsGenerationReport)
7171
}
7272
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/context/CgContext.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import org.utbot.framework.plugin.api.UtExecution
4545
import org.utbot.framework.plugin.api.UtMethod
4646
import org.utbot.framework.plugin.api.UtModel
4747
import org.utbot.framework.plugin.api.UtReferenceModel
48-
import org.utbot.framework.plugin.api.UtTestCase
48+
import org.utbot.framework.plugin.api.UtMethodTestSet
4949
import java.util.IdentityHashMap
5050
import kotlinx.collections.immutable.PersistentList
5151
import kotlinx.collections.immutable.PersistentMap
@@ -178,7 +178,7 @@ internal interface CgContextOwner {
178178
// map from a set of tests for a method to another map
179179
// which connects code generation error message
180180
// with the number of times it occurred
181-
val codeGenerationErrors: MutableMap<UtTestCase, MutableMap<String, Int>>
181+
val codeGenerationErrors: MutableMap<UtMethodTestSet, MutableMap<String, Int>>
182182

183183
// package for generated test class
184184
val testClassPackageName: String
@@ -418,7 +418,7 @@ internal data class CgContext(
418418
override var declaredExecutableRefs: PersistentMap<ExecutableId, CgVariable> = persistentMapOf(),
419419
override var thisInstance: CgValue? = null,
420420
override val methodArguments: MutableList<CgValue> = mutableListOf(),
421-
override val codeGenerationErrors: MutableMap<UtTestCase, MutableMap<String, Int>> = mutableMapOf(),
421+
override val codeGenerationErrors: MutableMap<UtMethodTestSet, MutableMap<String, Int>> = mutableMapOf(),
422422
override val testClassPackageName: String = classUnderTest.packageName,
423423
override var shouldOptimizeImports: Boolean = false,
424424
override var testClassCustomName: String? = null,

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ import org.utbot.framework.plugin.api.UtNullModel
117117
import org.utbot.framework.plugin.api.UtPrimitiveModel
118118
import org.utbot.framework.plugin.api.UtReferenceModel
119119
import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation
120-
import org.utbot.framework.plugin.api.UtTestCase
120+
import org.utbot.framework.plugin.api.UtMethodTestSet
121121
import org.utbot.framework.plugin.api.UtTimeoutException
122122
import org.utbot.framework.plugin.api.UtVoidModel
123123
import org.utbot.framework.plugin.api.onFailure
@@ -1208,19 +1208,19 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
12081208
private val expectedResultVarName = "expectedResult"
12091209
private val expectedErrorVarName = "expectedError"
12101210

1211-
fun createParameterizedTestMethod(utTestCase: UtTestCase, dataProviderMethodName: String): CgTestMethod? {
1212-
val methodUnderTest = utTestCase.method
1213-
val methodUnderTestParameters = utTestCase.method.callable.parameters
1211+
fun createParameterizedTestMethod(testSet: UtMethodTestSet, dataProviderMethodName: String): CgTestMethod? {
1212+
val methodUnderTest = testSet.method
1213+
val methodUnderTestParameters = testSet.method.callable.parameters
12141214

1215-
if (utTestCase.executions.isEmpty()) {
1215+
if (testSet.executions.isEmpty()) {
12161216
return null
12171217
}
12181218

12191219
//TODO: orientation on arbitrary execution may be misleading, but what is the alternative?
12201220
//may be a heuristic to select a model with minimal number of internal nulls should be used
1221-
val arbitraryExecution = utTestCase.executions
1221+
val arbitraryExecution = testSet.executions
12221222
.firstOrNull { it.result is UtExecutionSuccess && (it.result as UtExecutionSuccess).model !is UtNullModel }
1223-
?: utTestCase.executions.first()
1223+
?: testSet.executions.first()
12241224

12251225
return withTestMethodScope(arbitraryExecution) {
12261226
val testName = nameGenerator.parameterizedTestMethodName(dataProviderMethodName)
@@ -1252,7 +1252,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
12521252
)
12531253
}
12541254
val method = currentExecutable as MethodId
1255-
val containsFailureExecution = containsFailureExecution(utTestCase)
1255+
val containsFailureExecution = containsFailureExecution(testSet)
12561256
if (method.returnType != voidClassId) {
12571257
testArguments += CgParameterDeclaration(
12581258
expectedResultVarName, resultClassId(method.returnType),
@@ -1280,7 +1280,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
12801280
parameterized = true,
12811281
dataProviderMethodName
12821282
) {
1283-
if (containsFailureExecution(utTestCase)) {
1283+
if (containsFailureExecution(testSet)) {
12841284
+tryBlock(mainBody)
12851285
.catch(Throwable::class.java.id) { e ->
12861286
val pseudoExceptionVarName = when (codegenLanguage) {
@@ -1312,20 +1312,20 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
13121312
* Standard logic for generating each test case parameter code is used.
13131313
*/
13141314
fun createParameterizedTestDataProvider(
1315-
utTestCase: UtTestCase,
1315+
testSet: UtMethodTestSet,
13161316
dataProviderMethodName: String
13171317
): CgParameterizedTestDataProviderMethod {
13181318
val dataProviderStatements = mutableListOf<CgStatement>()
13191319
val dataProviderExceptions = mutableSetOf<ClassId>()
13201320

1321-
val argListLength = utTestCase.executions.size
1321+
val argListLength = testSet.executions.size
13221322
val argListDeclaration = createArgList(argListLength)
13231323
val argListVariable = argListDeclaration.variable
13241324

13251325
dataProviderStatements += argListDeclaration
13261326
dataProviderStatements += CgEmptyLine()
13271327

1328-
for ((execIndex, execution) in utTestCase.executions.withIndex()) {
1328+
for ((execIndex, execution) in testSet.executions.withIndex()) {
13291329
withTestMethodScope(execution) {
13301330
//collect arguments
13311331
val arguments = mutableListOf<CgExpression>()
@@ -1335,13 +1335,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
13351335
}
13361336

13371337
for ((paramIndex, paramModel) in execution.stateBefore.parameters.withIndex()) {
1338-
val argumentName = paramNames[utTestCase.method]?.get(paramIndex)
1338+
val argumentName = paramNames[testSet.method]?.get(paramIndex)
13391339
arguments += variableConstructor.getOrCreateVariable(paramModel, argumentName)
13401340
}
13411341

13421342
val method = currentExecutable as MethodId
13431343
val needsReturnValue = method.returnType != voidClassId
1344-
val containsFailureExecution = containsFailureExecution(utTestCase)
1344+
val containsFailureExecution = containsFailureExecution(testSet)
13451345
execution.result
13461346
.onSuccess {
13471347
if (needsReturnValue) {
@@ -1530,8 +1530,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
15301530
)
15311531
}
15321532

1533-
private fun containsFailureExecution(testCase: UtTestCase) =
1534-
testCase.executions.any { it.result is UtExecutionFailure }
1533+
private fun containsFailureExecution(testSet: UtMethodTestSet) =
1534+
testSet.executions.any { it.result is UtExecutionFailure }
15351535

15361536
private fun resultClassId(returnType: ClassId): ClassId = when (returnType) {
15371537
booleanClassId -> booleanWrapperClassId

0 commit comments

Comments
 (0)