Skip to content

Commit 08ded2a

Browse files
Rename UtTestCase #519 (#517)
1 parent d3b10e2 commit 08ded2a

File tree

36 files changed

+292
-343
lines changed

36 files changed

+292
-343
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ class BunchTestGeneratorCommand : GenerateTestsAbstractCommand(
104104

105105
val testClassName = "${classUnderTest.simpleName}Test"
106106

107-
val testCases = generateTestCases(
107+
val testSets = generateTestSets(
108108
targetMethods,
109109
searchDirectory = workingDirectory,
110110
chosenClassesToMockAlways = (Mocker.defaultSuperClassesToMockAlwaysNames + classesToMockAlways)
111111
.mapTo(mutableSetOf()) { ClassId(it) }
112112
)
113113

114-
val testClassBody = generateTest(classUnderTest, testClassName, testCases)
114+
val testClassBody = generateTest(classUnderTest, testClassName, testSets)
115115

116116
val outputArgAsFile = File(output ?: "")
117117
if (!outputArgAsFile.exists()) {

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

Lines changed: 5 additions & 5 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
@@ -153,12 +153,12 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
153153
protected fun loadClassBySpecifiedFqn(classFqn: String): KClass<*> =
154154
classLoader.loadClass(classFqn).kotlin
155155

156-
protected fun generateTestCases(
156+
protected fun generateTestSets(
157157
targetMethods: List<UtMethod<*>>,
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: 6 additions & 6 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
@@ -102,20 +102,20 @@ class GenerateTestsCommand :
102102

103103
val testClassName = output?.toPath()?.toFile()?.nameWithoutExtension
104104
?: "${classUnderTest.simpleName}Test"
105-
val testCases = generateTestCases(
105+
val testSets = generateTestSets(
106106
targetMethods,
107107
Paths.get(sourceCodeFile),
108108
searchDirectory = workingDirectory,
109109
chosenClassesToMockAlways = (Mocker.defaultSuperClassesToMockAlwaysNames + classesToMockAlways)
110110
.mapTo(mutableSetOf()) { ClassId(it) }
111111
)
112-
val testClassBody = generateTest(classUnderTest, testClassName, testCases)
112+
val testClassBody = generateTest(classUnderTest, testClassName, testSets)
113113

114114
if (printToStdOut) {
115115
logger.info { testClassBody }
116116
}
117117
if (sarifReport != null) {
118-
generateReport(targetClassFqn, testCases, testClassBody)
118+
generateReport(targetClassFqn, testSets, testClassBody)
119119
}
120120
saveToFile(testClassBody, output)
121121
}
@@ -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-api/src/main/kotlin/org/utbot/framework/plugin/api/ValueBasedApi.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66

77
package org.utbot.framework.plugin.api
88

9-
import kotlin.reflect.KClass
109
import org.apache.commons.lang3.builder.RecursiveToStringStyle
1110
import org.apache.commons.lang3.builder.ReflectionToStringBuilder
12-
import soot.jimple.JimpleBody
1311

14-
data class UtValueTestCase<R>(
12+
data class UtMethodValueTestSet<R>(
1513
val method: UtMethod<out R>,
1614
val executions: List<UtValueExecution<out R>> = emptyList(),
17-
val jimpleBody: JimpleBody? = null,
1815
val errors: Map<String, Int> = emptyMap(),
1916
)
2017

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

Lines changed: 16 additions & 16 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
@@ -51,7 +51,7 @@ object UtBotJavaApi {
5151
@JvmOverloads
5252
fun generate(
5353
methodsForGeneration: List<TestMethodInfo>,
54-
generatedTestCases: List<UtTestCase> = mutableListOf(),
54+
generatedTestCases: List<UtMethodTestSet> = mutableListOf(),
5555
destinationClassName: String,
5656
classpath: String,
5757
dependencyClassPath: String,
@@ -67,15 +67,15 @@ object UtBotJavaApi {
6767

6868
val utContext = UtContext(classUnderTest.classLoader)
6969

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

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

78-
testCases.addAll(generateUnitTests(concreteExecutor, methodsForGeneration, classUnderTest))
78+
testSets.addAll(generateUnitTests(concreteExecutor, methodsForGeneration, classUnderTest))
7979

8080
if (stopConcreteExecutorOnExit) {
8181
concreteExecutor.close()
@@ -96,32 +96,32 @@ object UtBotJavaApi {
9696
}
9797

9898
testGenerator.generateAsString(
99-
testCases,
99+
testSets,
100100
destinationClassName
101101
)
102102
}
103103
}
104104

105105
/**
106-
* Generates test cases using default workflow.
106+
* Generates test sets using default workflow.
107107
*
108-
* @see [fuzzingTestCases]
108+
* @see [fuzzingTestSets]
109109
*/
110110
@JvmStatic
111111
@JvmOverloads
112-
fun generateTestCases(
112+
fun generateTestSets(
113113
methodsForAutomaticGeneration: List<TestMethodInfo>,
114114
classUnderTest: Class<*>,
115115
classpath: String,
116116
dependencyClassPath: String,
117117
mockStrategyApi: MockStrategyApi = MockStrategyApi.OTHER_PACKAGES,
118118
generationTimeoutInMillis: Long = UtSettings.utBotGenerationTimeoutInMillis
119-
): MutableList<UtTestCase> {
119+
): MutableList<UtMethodTestSet> {
120120

121121
val utContext = UtContext(classUnderTest.classLoader)
122-
val testCases: MutableList<UtTestCase> = mutableListOf()
122+
val testSets: MutableList<UtMethodTestSet> = mutableListOf()
123123

124-
testCases.addAll(withUtContext(utContext) {
124+
testSets.addAll(withUtContext(utContext) {
125125
TestCaseGenerator
126126
.apply {
127127
init(
@@ -141,25 +141,25 @@ object UtBotJavaApi {
141141
)
142142
})
143143

144-
return testCases
144+
return testSets
145145
}
146146

147147
/**
148148
* Generates test cases using only fuzzing workflow.
149149
*
150-
* @see [generateTestCases]
150+
* @see [generateTestSets]
151151
*/
152152
@JvmStatic
153153
@JvmOverloads
154-
fun fuzzingTestCases(
154+
fun fuzzingTestSets(
155155
methodsForAutomaticGeneration: List<TestMethodInfo>,
156156
classUnderTest: Class<*>,
157157
classpath: String,
158158
dependencyClassPath: String,
159159
mockStrategyApi: MockStrategyApi = MockStrategyApi.OTHER_PACKAGES,
160160
generationTimeoutInMillis: Long = UtSettings.utBotGenerationTimeoutInMillis,
161161
primitiveValuesSupplier: CustomFuzzerValueSupplier = CustomFuzzerValueSupplier { null }
162-
): MutableList<UtTestCase> {
162+
): MutableList<UtMethodTestSet> {
163163
fun createPrimitiveModels(supplier: CustomFuzzerValueSupplier, classId: ClassId): Sequence<UtPrimitiveModel> =
164164
supplier
165165
.takeIf { classId.isPrimitive || classId.isPrimitiveWrapper || classId == stringClassId }
@@ -262,7 +262,7 @@ object UtBotJavaApi {
262262

263263
val utMethod = UtMethod(methodCallable, containingClass.kotlin)
264264

265-
UtTestCase(
265+
UtMethodTestSet(
266266
utMethod,
267267
listOf(utExecution)
268268
)

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,

0 commit comments

Comments
 (0)