diff --git a/utbot-cli/src/main/kotlin/org/utbot/cli/BunchTestGeneratorCommand.kt b/utbot-cli/src/main/kotlin/org/utbot/cli/BunchTestGeneratorCommand.kt index ead479b168..e2d19b5fcd 100644 --- a/utbot-cli/src/main/kotlin/org/utbot/cli/BunchTestGeneratorCommand.kt +++ b/utbot-cli/src/main/kotlin/org/utbot/cli/BunchTestGeneratorCommand.kt @@ -104,14 +104,14 @@ class BunchTestGeneratorCommand : GenerateTestsAbstractCommand( val testClassName = "${classUnderTest.simpleName}Test" - val testCases = generateTestCases( + val testSets = generateTestSets( targetMethods, searchDirectory = workingDirectory, chosenClassesToMockAlways = (Mocker.defaultSuperClassesToMockAlwaysNames + classesToMockAlways) .mapTo(mutableSetOf()) { ClassId(it) } ) - val testClassBody = generateTest(classUnderTest, testClassName, testCases) + val testClassBody = generateTest(classUnderTest, testClassName, testSets) val outputArgAsFile = File(output ?: "") if (!outputArgAsFile.exists()) { diff --git a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt index 8bcb4ee154..87fc8bab42 100644 --- a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt +++ b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt @@ -28,7 +28,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.TreatOverflowAsError import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.summary.summarize import java.io.File import java.lang.reflect.Method @@ -153,12 +153,12 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : protected fun loadClassBySpecifiedFqn(classFqn: String): KClass<*> = classLoader.loadClass(classFqn).kotlin - protected fun generateTestCases( + protected fun generateTestSets( targetMethods: List>, sourceCodeFile: Path? = null, searchDirectory: Path, chosenClassesToMockAlways: Set - ): List = + ): List = TestCaseGenerator.generate( targetMethods, mockStrategy, @@ -184,11 +184,11 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : } } - protected fun generateTest(classUnderTest: KClass<*>, testClassname: String, testCases: List): String = + protected fun generateTest(classUnderTest: KClass<*>, testClassname: String, testSets: List): String = initializeCodeGenerator( testFramework, classUnderTest - ).generateAsString(testCases, testClassname) + ).generateAsString(testSets, testClassname) protected fun initializeEngine(workingDirectory: Path) { val classPathNormalized = diff --git a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsCommand.kt b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsCommand.kt index c7ff55033b..1a6f7f56ed 100644 --- a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsCommand.kt +++ b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsCommand.kt @@ -11,7 +11,7 @@ import org.utbot.common.PathUtil.toPath import org.utbot.engine.Mocker import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.sarif.SarifReport @@ -102,20 +102,20 @@ class GenerateTestsCommand : val testClassName = output?.toPath()?.toFile()?.nameWithoutExtension ?: "${classUnderTest.simpleName}Test" - val testCases = generateTestCases( + val testSets = generateTestSets( targetMethods, Paths.get(sourceCodeFile), searchDirectory = workingDirectory, chosenClassesToMockAlways = (Mocker.defaultSuperClassesToMockAlwaysNames + classesToMockAlways) .mapTo(mutableSetOf()) { ClassId(it) } ) - val testClassBody = generateTest(classUnderTest, testClassName, testCases) + val testClassBody = generateTest(classUnderTest, testClassName, testSets) if (printToStdOut) { logger.info { testClassBody } } if (sarifReport != null) { - generateReport(targetClassFqn, testCases, testClassBody) + generateReport(targetClassFqn, testSets, testClassBody) } saveToFile(testClassBody, output) } @@ -128,7 +128,7 @@ class GenerateTestsCommand : } } - private fun generateReport(classFqn: String, testCases: List, testClassBody: String) = try { + private fun generateReport(classFqn: String, testSets: List, testClassBody: String) = try { // reassignments for smart casts val testsFilePath = output val projectRootPath = projectRoot @@ -143,7 +143,7 @@ class GenerateTestsCommand : else -> { val sourceFinding = SourceFindingStrategyDefault(classFqn, sourceCodeFile, testsFilePath, projectRootPath) - val report = SarifReport(testCases, testClassBody, sourceFinding).createReport() + val report = SarifReport(testSets, testClassBody, sourceFinding).createReport() saveToFile(report, sarifReport) println("The report was saved to \"$sarifReport\". You can open it using the VS Code extension \"Sarif Viewer\".") } diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 76d3643c6c..621e1377a2 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -90,34 +90,13 @@ data class UtMethod( } } -/** - * Test case. - * - * Note: it should not be transformed into data class since it is used as a key in maps. - * The clusters in it are mutable objects, therefore, we might have problems with hash because of it. - */ -@Suppress("unused") -class UtTestCase( +data class UtMethodTestSet( val method: UtMethod<*>, val executions: List = emptyList(), val jimpleBody: JimpleBody? = null, val errors: Map = emptyMap(), - private val clustersInfo: List> = listOf(null to executions.indices) -) { - operator fun component1() = method - operator fun component2() = executions - operator fun component3() = jimpleBody - operator fun component4() = errors - operator fun component5() = clustersInfo - - fun copy( - method: UtMethod<*> = this.method, - executions: List = this.executions, - jimpleBody: JimpleBody? = this.jimpleBody, - errors: Map = this.errors, - clustersInfo: List> = this.clustersInfo - ) = UtTestCase(method, executions, jimpleBody, errors, clustersInfo) -} + val clustersInfo: List> = listOf(null to executions.indices) +) data class Step( val stmt: Stmt, diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/ValueBasedApi.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/ValueBasedApi.kt index 84341b008e..a4d3d9e763 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/ValueBasedApi.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/ValueBasedApi.kt @@ -6,15 +6,12 @@ package org.utbot.framework.plugin.api -import kotlin.reflect.KClass import org.apache.commons.lang3.builder.RecursiveToStringStyle import org.apache.commons.lang3.builder.ReflectionToStringBuilder -import soot.jimple.JimpleBody -data class UtValueTestCase( +data class UtMethodValueTestSet( val method: UtMethod, val executions: List> = emptyList(), - val jimpleBody: JimpleBody? = null, val errors: Map = emptyMap(), ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt index 8c94862f84..aed5a15585 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt @@ -20,7 +20,7 @@ import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtPrimitiveModel -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.isPrimitive @@ -50,7 +50,7 @@ object UtBotJavaApi { @JvmOverloads fun generate( methodsForGeneration: List, - generatedTestCases: List = mutableListOf(), + generatedTestCases: List = mutableListOf(), destinationClassName: String, classpath: String, dependencyClassPath: String, @@ -66,7 +66,7 @@ object UtBotJavaApi { val utContext = UtContext(classUnderTest.classLoader) - val testCases: MutableList = generatedTestCases.toMutableList() + val testSets: MutableList = generatedTestCases.toMutableList() val concreteExecutor = ConcreteExecutor( UtExecutionInstrumentation, @@ -74,7 +74,7 @@ object UtBotJavaApi { dependencyClassPath ) - testCases.addAll(generateUnitTests(concreteExecutor, methodsForGeneration, classUnderTest)) + testSets.addAll(generateUnitTests(concreteExecutor, methodsForGeneration, classUnderTest)) if (stopConcreteExecutorOnExit) { concreteExecutor.close() @@ -95,32 +95,32 @@ object UtBotJavaApi { } testGenerator.generateAsString( - testCases, + testSets, destinationClassName ) } } /** - * Generates test cases using default workflow. + * Generates test sets using default workflow. * - * @see [fuzzingTestCases] + * @see [fuzzingTestSets] */ @JvmStatic @JvmOverloads - fun generateTestCases( + fun generateTestSets( methodsForAutomaticGeneration: List, classUnderTest: Class<*>, classpath: String, dependencyClassPath: String, mockStrategyApi: MockStrategyApi = MockStrategyApi.OTHER_PACKAGES, generationTimeoutInMillis: Long = UtSettings.utBotGenerationTimeoutInMillis - ): MutableList { + ): MutableList { val utContext = UtContext(classUnderTest.classLoader) - val testCases: MutableList = mutableListOf() + val testSets: MutableList = mutableListOf() - testCases.addAll(withUtContext(utContext) { + testSets.addAll(withUtContext(utContext) { TestCaseGenerator .apply { init( @@ -140,17 +140,17 @@ object UtBotJavaApi { ) }) - return testCases + return testSets } /** * Generates test cases using only fuzzing workflow. * - * @see [generateTestCases] + * @see [generateTestSets] */ @JvmStatic @JvmOverloads - fun fuzzingTestCases( + fun fuzzingTestSets( methodsForAutomaticGeneration: List, classUnderTest: Class<*>, classpath: String, @@ -158,7 +158,7 @@ object UtBotJavaApi { mockStrategyApi: MockStrategyApi = MockStrategyApi.OTHER_PACKAGES, generationTimeoutInMillis: Long = UtSettings.utBotGenerationTimeoutInMillis, primitiveValuesSupplier: CustomFuzzerValueSupplier = CustomFuzzerValueSupplier { null } - ): MutableList { + ): MutableList { fun createPrimitiveModels(supplier: CustomFuzzerValueSupplier, classId: ClassId): Sequence = supplier .takeIf { classId.isPrimitive || classId.isPrimitiveWrapper || classId == stringClassId } @@ -259,7 +259,7 @@ object UtBotJavaApi { val utMethod = UtMethod(methodCallable, containingClass.kotlin) - UtTestCase( + UtMethodTestSet( utMethod, listOf(utExecution) ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt index 6ef3f980fb..349f526e5c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt @@ -15,7 +15,7 @@ import org.utbot.framework.codegen.model.visitor.CgAbstractRenderer import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.MockFramework import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.id class CodeGenerator { @@ -56,17 +56,17 @@ class CodeGenerator { } //TODO: we support custom test class name only in utbot-online, probably support them in plugin as well - fun generateAsString(testCases: Collection, testClassCustomName: String? = null): String = - generateAsStringWithTestReport(testCases, testClassCustomName).generatedCode + fun generateAsString(testSets: Collection, testClassCustomName: String? = null): String = + generateAsStringWithTestReport(testSets, testClassCustomName).generatedCode //TODO: we support custom test class name only in utbot-online, probably support them in plugin as well fun generateAsStringWithTestReport( - testCases: Collection, + testSets: Collection, testClassCustomName: String? = null, ): TestsCodeWithTestReport = withCustomContext(testClassCustomName) { context.withClassScope { - val testClassFile = CgTestClassConstructor(context).construct(testCases) + val testClassFile = CgTestClassConstructor(context).construct(testSets) TestsCodeWithTestReport(renderClassFile(testClassFile), testClassFile.testsGenerationReport) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/context/CgContext.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/context/CgContext.kt index 37e3b3f2f8..7b10d5d469 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/context/CgContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/context/CgContext.kt @@ -45,7 +45,7 @@ import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtReferenceModel -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import java.util.IdentityHashMap import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.PersistentMap @@ -178,7 +178,7 @@ internal interface CgContextOwner { // map from a set of tests for a method to another map // which connects code generation error message // with the number of times it occurred - val codeGenerationErrors: MutableMap> + val codeGenerationErrors: MutableMap> // package for generated test class val testClassPackageName: String @@ -418,7 +418,7 @@ internal data class CgContext( override var declaredExecutableRefs: PersistentMap = persistentMapOf(), override var thisInstance: CgValue? = null, override val methodArguments: MutableList = mutableListOf(), - override val codeGenerationErrors: MutableMap> = mutableMapOf(), + override val codeGenerationErrors: MutableMap> = mutableMapOf(), override val testClassPackageName: String = classUnderTest.packageName, override var shouldOptimizeImports: Boolean = false, override var testClassCustomName: String? = null, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt index b1ab03e5db..5eb26f42d7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt @@ -117,7 +117,7 @@ import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.UtPrimitiveModel import org.utbot.framework.plugin.api.UtReferenceModel import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.UtTimeoutException import org.utbot.framework.plugin.api.UtVoidModel import org.utbot.framework.plugin.api.onFailure @@ -1208,19 +1208,19 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c private val expectedResultVarName = "expectedResult" private val expectedErrorVarName = "expectedError" - fun createParameterizedTestMethod(utTestCase: UtTestCase, dataProviderMethodName: String): CgTestMethod? { - val methodUnderTest = utTestCase.method - val methodUnderTestParameters = utTestCase.method.callable.parameters + fun createParameterizedTestMethod(testSet: UtMethodTestSet, dataProviderMethodName: String): CgTestMethod? { + val methodUnderTest = testSet.method + val methodUnderTestParameters = testSet.method.callable.parameters - if (utTestCase.executions.isEmpty()) { + if (testSet.executions.isEmpty()) { return null } //TODO: orientation on arbitrary execution may be misleading, but what is the alternative? //may be a heuristic to select a model with minimal number of internal nulls should be used - val arbitraryExecution = utTestCase.executions + val arbitraryExecution = testSet.executions .firstOrNull { it.result is UtExecutionSuccess && (it.result as UtExecutionSuccess).model !is UtNullModel } - ?: utTestCase.executions.first() + ?: testSet.executions.first() return withTestMethodScope(arbitraryExecution) { val testName = nameGenerator.parameterizedTestMethodName(dataProviderMethodName) @@ -1252,7 +1252,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c ) } val method = currentExecutable as MethodId - val containsFailureExecution = containsFailureExecution(utTestCase) + val containsFailureExecution = containsFailureExecution(testSet) if (method.returnType != voidClassId) { testArguments += CgParameterDeclaration( expectedResultVarName, resultClassId(method.returnType), @@ -1280,7 +1280,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c parameterized = true, dataProviderMethodName ) { - if (containsFailureExecution(utTestCase)) { + if (containsFailureExecution(testSet)) { +tryBlock(mainBody) .catch(Throwable::class.java.id) { e -> val pseudoExceptionVarName = when (codegenLanguage) { @@ -1312,20 +1312,20 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c * Standard logic for generating each test case parameter code is used. */ fun createParameterizedTestDataProvider( - utTestCase: UtTestCase, + testSet: UtMethodTestSet, dataProviderMethodName: String ): CgParameterizedTestDataProviderMethod { val dataProviderStatements = mutableListOf() val dataProviderExceptions = mutableSetOf() - val argListLength = utTestCase.executions.size + val argListLength = testSet.executions.size val argListDeclaration = createArgList(argListLength) val argListVariable = argListDeclaration.variable dataProviderStatements += argListDeclaration dataProviderStatements += CgEmptyLine() - for ((execIndex, execution) in utTestCase.executions.withIndex()) { + for ((execIndex, execution) in testSet.executions.withIndex()) { withTestMethodScope(execution) { //collect arguments val arguments = mutableListOf() @@ -1335,13 +1335,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c } for ((paramIndex, paramModel) in execution.stateBefore.parameters.withIndex()) { - val argumentName = paramNames[utTestCase.method]?.get(paramIndex) + val argumentName = paramNames[testSet.method]?.get(paramIndex) arguments += variableConstructor.getOrCreateVariable(paramModel, argumentName) } val method = currentExecutable as MethodId val needsReturnValue = method.returnType != voidClassId - val containsFailureExecution = containsFailureExecution(utTestCase) + val containsFailureExecution = containsFailureExecution(testSet) execution.result .onSuccess { if (needsReturnValue) { @@ -1530,8 +1530,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c ) } - private fun containsFailureExecution(testCase: UtTestCase) = - testCase.executions.any { it.result is UtExecutionFailure } + private fun containsFailureExecution(testSet: UtMethodTestSet) = + testSet.executions.any { it.result is UtExecutionFailure } private fun resultClassId(returnType: ClassId): ClassId = when (returnType) { booleanClassId -> booleanWrapperClassId diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgTestClassConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgTestClassConstructor.kt index 8475b4363c..afd7c44f4c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgTestClassConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgTestClassConstructor.kt @@ -25,7 +25,7 @@ import org.utbot.framework.codegen.model.tree.buildTestClassFile import org.utbot.framework.codegen.model.visitor.importUtilMethodDependencies import org.utbot.framework.plugin.api.MethodId import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.description import kotlin.reflect.KClass @@ -41,18 +41,18 @@ internal class CgTestClassConstructor(val context: CgContext) : private val testsGenerationReport: TestsGenerationReport = TestsGenerationReport() /** - * Given a list of test cases constructs CgTestClass + * Given a list of test sets constructs CgTestClass */ - fun construct(testCases: Collection): CgTestClassFile { + fun construct(testSets: Collection): CgTestClassFile { return buildTestClassFile { testClass = buildTestClass { // TODO: obtain test class from plugin id = currentTestClass body = buildTestClassBody { cgDataProviderMethods.clear() - for (testCase in testCases) { - updateCurrentExecutable(testCase.method) - val currentMethodUnderTestRegions = construct(testCase) + for (testSet in testSets) { + updateCurrentExecutable(testSet.method) + val currentMethodUnderTestRegions = construct(testSet) val executableUnderTestCluster = CgExecutableUnderTestCluster( "Test suites for executable $currentExecutable", currentMethodUnderTestRegions @@ -76,8 +76,8 @@ internal class CgTestClassConstructor(val context: CgContext) : } } - private fun construct(testCase: UtTestCase): List> { - val (methodUnderTest, executions, _, _, clustersInfo) = testCase + private fun construct(testSet: UtMethodTestSet): List> { + val (methodUnderTest, executions, _, _, clustersInfo) = testSet val regions = mutableListOf>() val requiredFields = mutableListOf() @@ -89,7 +89,7 @@ internal class CgTestClassConstructor(val context: CgContext) : for (i in executionIndices) { runCatching { currentTestCaseTestMethods += methodConstructor.createTestMethod(methodUnderTest, executions[i]) - }.onFailure { e -> processFailure(testCase, e) } + }.onFailure { e -> processFailure(testSet, e) } } val clusterHeader = clusterSummary?.header val clusterContent = clusterSummary?.content @@ -97,43 +97,43 @@ internal class CgTestClassConstructor(val context: CgContext) : ?.let { CgTripleSlashMultilineComment(it) } regions += CgTestMethodCluster(clusterHeader, clusterContent, currentTestCaseTestMethods) - testsGenerationReport.addTestsByType(testCase, currentTestCaseTestMethods) + testsGenerationReport.addTestsByType(testSet, currentTestCaseTestMethods) } } ParametrizedTestSource.PARAMETRIZE -> { runCatching { - val dataProviderMethodName = nameGenerator.dataProviderMethodNameFor(testCase.method) + val dataProviderMethodName = nameGenerator.dataProviderMethodNameFor(testSet.method) val parameterizedTestMethod = - methodConstructor.createParameterizedTestMethod(testCase, dataProviderMethodName) + methodConstructor.createParameterizedTestMethod(testSet, dataProviderMethodName) if (parameterizedTestMethod != null) { requiredFields += parameterizedTestMethod.requiredFields cgDataProviderMethods += - methodConstructor.createParameterizedTestDataProvider(testCase, dataProviderMethodName) + methodConstructor.createParameterizedTestDataProvider(testSet, dataProviderMethodName) regions += CgSimpleRegion( "Parameterized test for method ${methodUnderTest.displayName}", listOf(parameterizedTestMethod), ) } - }.onFailure { error -> processFailure(testCase, error) } + }.onFailure { error -> processFailure(testSet, error) } } } - val errors = testCase.allErrors + val errors = testSet.allErrors if (errors.isNotEmpty()) { - regions += methodConstructor.errorMethod(testCase.method, errors) - testsGenerationReport.addMethodErrors(testCase, errors) + regions += methodConstructor.errorMethod(testSet.method, errors) + testsGenerationReport.addMethodErrors(testSet, errors) } return regions } - private fun processFailure(testCase: UtTestCase, failure: Throwable) { + private fun processFailure(testSet: UtMethodTestSet, failure: Throwable) { codeGenerationErrors - .getOrPut(testCase) { mutableMapOf() } + .getOrPut(testSet) { mutableMapOf() } .merge(failure.description, 1, Int::plus) } @@ -168,9 +168,9 @@ internal class CgTestClassConstructor(val context: CgContext) : } /** - * Engine errors + codegen errors for a given UtTestCase + * Engine errors + codegen errors for a given [UtMethodTestSet] */ - private val UtTestCase.allErrors: Map + private val UtMethodTestSet.allErrors: Map get() = errors + codeGenerationErrors.getOrDefault(this, mapOf()) } @@ -193,12 +193,12 @@ data class TestsGenerationReport( var summaryMessage: () -> String = { "Unit tests for $classUnderTest were generated successfully." } val initialWarnings: MutableList<() -> String> = mutableListOf() - fun addMethodErrors(testCase: UtTestCase, errors: Map) { - this.errors[testCase.method] = errors + fun addMethodErrors(testSet: UtMethodTestSet, errors: Map) { + this.errors[testSet.method] = errors } - fun addTestsByType(testCase: UtTestCase, testMethods: List) { - with(testCase.method) { + fun addTestsByType(testSet: UtMethodTestSet, testMethods: List) { + with(testSet.method) { executables += this testMethods.forEach { diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/coverage/CoverageCalculator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/coverage/CoverageCalculator.kt index d7c61de465..9551b3c207 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/coverage/CoverageCalculator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/coverage/CoverageCalculator.kt @@ -2,7 +2,7 @@ package org.utbot.framework.coverage import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtValueExecution -import org.utbot.framework.plugin.api.UtValueTestCase +import org.utbot.framework.plugin.api.UtMethodValueTestSet import org.utbot.framework.plugin.api.util.signature import org.utbot.framework.util.anyInstance import org.utbot.instrumentation.ConcreteExecutor @@ -140,8 +140,8 @@ class MemoryClassLoader : ClassLoader() { } } -fun classCoverage(testCases: List>): Coverage = - testCases.map { methodCoverageWithJaCoCo(it.method, it.executions) }.toClassCoverage() +fun classCoverage(testSets: List>): Coverage = + testSets.map { methodCoverageWithJaCoCo(it.method, it.executions) }.toClassCoverage() fun methodCoverageWithJaCoCo(utMethod: UtMethod<*>, executions: List>): Coverage { val methodSignature = utMethod.callable.signature diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index 653637d947..6dd1a87058 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -142,8 +142,8 @@ object TestCaseGenerator { chosenClassesToMockAlways: Set = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id }, methodsGenerationTimeout: Long = utBotGenerationTimeoutInMillis, generate: (engine: UtBotSymbolicEngine) -> Flow = ::createDefaultFlow - ): List { - if (isCanceled()) return methods.map { UtTestCase(it) } + ): List { + if (isCanceled()) return methods.map { UtMethodTestSet(it) } val executionStartInMillis = System.currentTimeMillis() val executionTimeEstimator = ExecutionTimeEstimator(methodsGenerationTimeout, methods.size) @@ -218,7 +218,7 @@ object TestCaseGenerator { return methods.map { method -> - UtTestCase( + UtMethodTestSet( method, minimizeExecutions(method2executions.getValue(method)), jimpleBody(method), diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt index 408756e25f..b4c88c5d8f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt @@ -4,7 +4,7 @@ import org.utbot.framework.codegen.ForceStaticMocking import org.utbot.framework.codegen.NoStaticMocking import org.utbot.framework.codegen.model.CodeGenerator import org.utbot.framework.plugin.api.TestCaseGenerator -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.sarif.SarifReport import org.utbot.sarif.SourceFindingStrategy import org.utbot.summary.summarize @@ -32,11 +32,11 @@ class GenerateTestsAndSarifReportFacade( ) { initializeEngine(runtimeClasspath, workingDirectory) - val testCases = generateTestCases(targetClass, workingDirectory) - val testClassBody = generateTestCode(targetClass, testCases) + val testSets = generateTestSets(targetClass, workingDirectory) + val testClassBody = generateTestCode(targetClass, testSets) targetClass.testsCodeFile.writeText(testClassBody) - generateReport(targetClass, testCases, testClassBody, sourceFindingStrategy) + generateReport(targetClass, testSets, testClassBody, sourceFindingStrategy) } companion object { @@ -69,7 +69,7 @@ class GenerateTestsAndSarifReportFacade( TestCaseGenerator.init(workingDirectory, classPath, dependencyPaths) } - private fun generateTestCases(targetClass: TargetClassWrapper, workingDirectory: Path): List = + private fun generateTestSets(targetClass: TargetClassWrapper, workingDirectory: Path): List = TestCaseGenerator.generate( targetClass.targetMethods, sarifProperties.mockStrategy, @@ -79,9 +79,9 @@ class GenerateTestsAndSarifReportFacade( it.summarize(targetClass.sourceCodeFile, workingDirectory) } - private fun generateTestCode(targetClass: TargetClassWrapper, testCases: List): String = + private fun generateTestCode(targetClass: TargetClassWrapper, testSets: List): String = initializeCodeGenerator(targetClass) - .generateAsString(testCases, targetClass.testsCodeFile.nameWithoutExtension) + .generateAsString(testSets, targetClass.testsCodeFile.nameWithoutExtension) private fun initializeCodeGenerator(targetClass: TargetClassWrapper) = CodeGenerator().apply { @@ -105,11 +105,11 @@ class GenerateTestsAndSarifReportFacade( */ private fun generateReport( targetClass: TargetClassWrapper, - testCases: List, + testSets: List, testClassBody: String, sourceFinding: SourceFindingStrategy ) { - val sarifReport = SarifReport(testCases, testClassBody, sourceFinding).createReport() + val sarifReport = SarifReport(testSets, testClassBody, sourceFinding).createReport() targetClass.sarifReportFile.writeText(sarifReport) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/util/EngineUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/util/EngineUtils.kt index 572094f0c2..8d04ac748f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/util/EngineUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/util/EngineUtils.kt @@ -6,8 +6,8 @@ import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.MissingState import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtTestCase -import org.utbot.framework.plugin.api.UtValueTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet +import org.utbot.framework.plugin.api.UtMethodValueTestSet import org.utbot.framework.plugin.api.UtVoidModel import org.utbot.framework.plugin.api.classId import org.utbot.framework.plugin.api.id @@ -17,7 +17,6 @@ import org.utbot.framework.plugin.api.util.methodId import org.utbot.framework.plugin.api.util.objectClassId import java.util.concurrent.atomic.AtomicInteger import soot.SootMethod -import soot.jimple.JimpleBody @Suppress("DEPRECATION") @@ -74,9 +73,9 @@ val instanceCounter = AtomicInteger(0) fun nextModelName(base: String): String = "$base${instanceCounter.incrementAndGet()}" -fun UtTestCase.toValueTestCase(jimpleBody: JimpleBody? = null): UtValueTestCase<*> { +fun UtMethodTestSet.toValueTestCase(): UtMethodValueTestSet<*> { val valueExecutions = executions.map { ValueConstructor().construct(it) } - return UtValueTestCase(method, valueExecutions, jimpleBody, errors) + return UtMethodValueTestSet(method, valueExecutions, errors) } fun UtModel.isUnit(): Boolean = diff --git a/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt b/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt index 2615ab7384..4c8d23254a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt @@ -13,7 +13,7 @@ import org.utbot.framework.plugin.api.UtImplicitlyThrownException import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtOverflowFailure -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet /** * Used for the SARIF report creation by given test cases and generated tests code. @@ -24,7 +24,7 @@ import org.utbot.framework.plugin.api.UtTestCase * [Sample report](https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#example-with-minimum-required-properties) */ class SarifReport( - private val testCases: List, + private val testSets: List, private val generatedTestsCode: String, private val sourceFinding: SourceFindingStrategy ) { @@ -70,11 +70,11 @@ class SarifReport( val sarifResults = mutableListOf() val sarifRules = mutableSetOf() - for (testCase in testCases) { - for (execution in testCase.executions) { + for (testSet in testSets) { + for (execution in testSet.executions) { if (shouldProcessExecutionResult(execution.result)) { val (sarifResult, sarifRule) = processUncheckedException( - method = testCase.method, + method = testSet.method, utExecution = execution, uncheckedException = execution.result as UtExecutionFailure ) diff --git a/utbot-framework/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java b/utbot-framework/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java index 89ffcb5157..d21fac1a7a 100644 --- a/utbot-framework/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java +++ b/utbot-framework/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java @@ -34,7 +34,7 @@ import org.utbot.framework.plugin.api.UtModel; import org.utbot.framework.plugin.api.UtNullModel; import org.utbot.framework.plugin.api.UtPrimitiveModel; -import org.utbot.framework.plugin.api.UtTestCase; +import org.utbot.framework.plugin.api.UtMethodTestSet; import org.utbot.framework.plugin.api.util.UtContext; import org.utbot.framework.util.Snippet; import java.io.File; @@ -148,7 +148,7 @@ public void testMultiMethodClass() { thirdMethodUnderTest, thirdMethodState); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Arrays.asList(firstTestMethodInfo, secondTestMethodInfo, thirdTestMethodInfo), MultiMethodExample.class, classpath, @@ -159,7 +159,7 @@ public void testMultiMethodClass() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -220,7 +220,7 @@ public void testCustomPackage() { Class.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -235,7 +235,7 @@ public void testCustomPackage() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -319,7 +319,7 @@ public void testOnObjectWithAssignedArrayField() { AssignedArray.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -334,7 +334,7 @@ public void testOnObjectWithAssignedArrayField() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -405,7 +405,7 @@ public void testClassRef() { Class.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -420,7 +420,7 @@ public void testClassRef() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -510,7 +510,7 @@ public void testObjectWithPublicFields() { DirectAccess.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -525,7 +525,7 @@ public void testObjectWithPublicFields() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -613,7 +613,7 @@ public void testObjectWithPublicFieldsWithAssembleModel() { DirectAccess.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -628,7 +628,7 @@ public void testObjectWithPublicFieldsWithAssembleModel() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -702,7 +702,7 @@ public void testOnObjectWithArrayOfPrimitiveArrays() { ArrayOfPrimitiveArrays.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -717,7 +717,7 @@ public void testOnObjectWithArrayOfPrimitiveArrays() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -797,7 +797,7 @@ public void testProvided3() { B.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -813,7 +813,7 @@ public void testProvided3() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -869,7 +869,7 @@ public void testCustomAssertion() { int.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -885,7 +885,7 @@ public void testCustomAssertion() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -981,7 +981,7 @@ public void testProvided3Reused() { int.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -997,7 +997,7 @@ public void testProvided3Reused() { String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -1054,7 +1054,7 @@ public void testProvided3Reused() { String.class ); - List utTestCases1 = UtBotJavaApi.generateTestCases( + List testSets1 = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest2, @@ -1070,7 +1070,7 @@ public void testProvided3Reused() { String generationResultWithConcreteExecutionOnly2 = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases1, + testSets1, destinationClassName, classpath, dependencyClassPath, @@ -1119,7 +1119,7 @@ public void testProvided1() { int.class, int.class, String.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -1135,7 +1135,7 @@ public void testProvided1() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -1195,7 +1195,7 @@ public void testOnObjectWithArrayOfComplexArrays() { ArrayOfComplexArrays.class ); - List utTestCases = UtBotJavaApi.generateTestCases( + List testSets = UtBotJavaApi.generateTestSets( Collections.singletonList( new TestMethodInfo( methodUnderTest, @@ -1211,7 +1211,7 @@ public void testOnObjectWithArrayOfComplexArrays() { String generationResult = UtBotJavaApi.generate( Collections.emptyList(), - utTestCases, + testSets, destinationClassName, classpath, dependencyClassPath, @@ -1273,7 +1273,7 @@ public void testFuzzingSimple() { TestMethodInfo methodInfo = new TestMethodInfo( methodUnderTest, methodState); - List utTestCases1 = UtBotJavaApi.fuzzingTestCases( + List testSets1 = UtBotJavaApi.fuzzingTestSets( Collections.singletonList( methodInfo ), @@ -1292,7 +1292,7 @@ public void testFuzzingSimple() { String generate = UtBotJavaApi.generate( Collections.singletonList(methodInfo), - utTestCases1, + testSets1, destinationClassName, classpath, dependencyClassPath, diff --git a/utbot-framework/src/test/kotlin/org/utbot/examples/CodeGenerationIntegrationTest.kt b/utbot-framework/src/test/kotlin/org/utbot/examples/CodeGenerationIntegrationTest.kt index 41ac541be4..90f25d73bf 100644 --- a/utbot-framework/src/test/kotlin/org/utbot/examples/CodeGenerationIntegrationTest.kt +++ b/utbot-framework/src/test/kotlin/org/utbot/examples/CodeGenerationIntegrationTest.kt @@ -12,7 +12,7 @@ import org.utbot.framework.codegen.Stage import org.utbot.framework.codegen.StageStatusCheck import org.utbot.framework.codegen.TestExecution import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.instrumentation.ConcreteExecutor import kotlin.reflect.KClass import mu.KotlinLogging @@ -41,12 +41,12 @@ abstract class CodeGenerationIntegrationTest( CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN) ) ) { - private val testCases: MutableList = arrayListOf() + private val testSets: MutableList = arrayListOf() data class CodeGenerationLanguageLastStage(val language: CodegenLanguage, val lastStage: Stage = TestExecution) - fun processTestCase(testCase: UtTestCase) { - if (testCodeGeneration) testCases += testCase + fun processTestCase(testSet: UtMethodTestSet) { + if (testCodeGeneration) testSets += testSet } protected fun withEnabledTestingCodeGeneration(testCodeGeneration: Boolean, block: () -> Unit) { @@ -65,7 +65,7 @@ abstract class CodeGenerationIntegrationTest( if (testCodeGeneration) { packageResult.getOrPut(pkg) { mutableListOf() } += CodeGenerationTestCases( testClass, - testCases, + testSets, languagesLastStages ) } @@ -114,7 +114,7 @@ abstract class CodeGenerationIntegrationTest( lastStage = codeGenerationTestCases.languagePipelines.single { it.language == language }.lastStage, status = ExecutionStatus.SUCCESS ), - codeGenerationTestCases.testCases + codeGenerationTestCases.testSets ) } @@ -146,7 +146,7 @@ abstract class CodeGenerationIntegrationTest( data class CodeGenerationTestCases( val testClass: KClass<*>, - val testCases: List, + val testSets: List, val languagePipelines: List ) diff --git a/utbot-framework/src/test/kotlin/org/utbot/examples/TestSpecificTestCaseGenerator.kt b/utbot-framework/src/test/kotlin/org/utbot/examples/TestSpecificTestCaseGenerator.kt index 0359fadbab..1c6219e555 100644 --- a/utbot-framework/src/test/kotlin/org/utbot/examples/TestSpecificTestCaseGenerator.kt +++ b/utbot-framework/src/test/kotlin/org/utbot/examples/TestSpecificTestCaseGenerator.kt @@ -12,12 +12,12 @@ import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.UtError import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.util.jimpleBody import java.nio.file.Path /** - * Special [UtTestCase] generator for test methods that has a correct + * Special [UtMethodTestSet] generator for test methods that has a correct * wrapper for suspend function [TestCaseGenerator.generateAsync]. */ object TestSpecificTestCaseGenerator { @@ -30,10 +30,10 @@ object TestSpecificTestCaseGenerator { isCanceled: () -> Boolean = { false }, ) = TestCaseGenerator.init(buildDir, classpath, dependencyPaths, engineActions, isCanceled) - fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtTestCase { + fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtMethodTestSet { logger.trace { "UtSettings:${System.lineSeparator()}" + UtSettings.toString() } - if (TestCaseGenerator.isCanceled()) return UtTestCase(method) + if (TestCaseGenerator.isCanceled()) return UtMethodTestSet(method) val executions = mutableListOf() val errors = mutableMapOf() @@ -50,6 +50,6 @@ object TestSpecificTestCaseGenerator { } val minimizedExecutions = TestCaseGenerator.minimizeExecutions(executions) - return UtTestCase(method, minimizedExecutions, jimpleBody(method), errors) + return UtMethodTestSet(method, minimizedExecutions, jimpleBody(method), errors) } } \ No newline at end of file diff --git a/utbot-framework/src/test/kotlin/org/utbot/examples/UtModelTestCaseChecker.kt b/utbot-framework/src/test/kotlin/org/utbot/examples/UtModelTestCaseChecker.kt index 6c09c653c1..40582b9214 100644 --- a/utbot-framework/src/test/kotlin/org/utbot/examples/UtModelTestCaseChecker.kt +++ b/utbot-framework/src/test/kotlin/org/utbot/examples/UtModelTestCaseChecker.kt @@ -21,7 +21,7 @@ import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtExecutionResult import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.exceptionOrNull import org.utbot.framework.plugin.api.getOrThrow import org.utbot.framework.plugin.api.util.UtContext @@ -93,19 +93,19 @@ internal abstract class UtModelTestCaseChecker( val utMethod = UtMethod.from(method) withUtContext(UtContext(utMethod.clazz.java.classLoader)) { - val testCase = executions(utMethod, mockStrategy) + val testSet = executions(utMethod, mockStrategy) - assertTrue(testCase.errors.isEmpty()) { - "We have errors: ${testCase.errors.entries.map { "${it.value}: ${it.key}" }.prettify()}" + assertTrue(testSet.errors.isEmpty()) { + "We have errors: ${testSet.errors.entries.map { "${it.value}: ${it.key}" }.prettify()}" } - val executions = testCase.executions + val executions = testSet.executions assertTrue(branches(executions.size)) { "Branch count matcher '$branches' fails for #executions=${executions.size}: ${executions.prettify()}" } executions.checkMatchers(matchers, arguments) - processTestCase(testCase) + processTestCase(testSet) } } @@ -131,7 +131,7 @@ internal abstract class UtModelTestCaseChecker( private fun executions( method: UtMethod<*>, mockStrategy: MockStrategyApi - ): UtTestCase { + ): UtMethodTestSet { val classLocation = locateClass(method.clazz) if (classLocation != previousClassLocation) { buildDir = findPathToClassFiles(classLocation) diff --git a/utbot-framework/src/test/kotlin/org/utbot/examples/UtValueTestCaseChecker.kt b/utbot-framework/src/test/kotlin/org/utbot/examples/UtValueTestCaseChecker.kt index 6b9ca65657..4828aeaced 100644 --- a/utbot-framework/src/test/kotlin/org/utbot/examples/UtValueTestCaseChecker.kt +++ b/utbot-framework/src/test/kotlin/org/utbot/examples/UtValueTestCaseChecker.kt @@ -49,12 +49,11 @@ import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtMockValue import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtPrimitiveModel -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.UtValueExecution import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.withUtContext -import org.utbot.framework.util.jimpleBody import org.utbot.framework.util.toValueTestCase import org.utbot.summary.summarize import java.io.File @@ -2293,7 +2292,7 @@ abstract class UtValueTestCaseChecker( val methodWithStrategy = MethodWithMockStrategy(utMethod, mockStrategy, resetNonFinalFieldsAfterClinit) - val (testCase, coverage) = analyzedMethods.getOrPut(methodWithStrategy) { + val (testSet, coverage) = analyzedMethods.getOrPut(methodWithStrategy) { walk(utMethod, mockStrategy) } @@ -2301,13 +2300,13 @@ abstract class UtValueTestCaseChecker( // TODO JIRA:1407 } - val testClass = testCase.method.clazz + val testClass = testSet.method.clazz val stageStatusCheck = StageStatusCheck( firstStage = CodeGeneration, lastStage = TestExecution, status = ExecutionStatus.SUCCESS ) - val classStages = listOf(ClassStages(testClass, stageStatusCheck, listOf(testCase))) + val classStages = listOf(ClassStages(testClass, stageStatusCheck, listOf(testSet))) TestCodeGeneratorPipeline(testFrameworkConfiguration).runClassesCodeGenerationTests(classStages) } @@ -2337,17 +2336,17 @@ abstract class UtValueTestCaseChecker( computeAdditionalDependenciesClasspathAndBuildDir(utMethod, additionalDependencies) withUtContext(UtContext(utMethod.clazz.java.classLoader)) { - val (testCase, coverage) = if (coverageMatcher is DoNotCalculate) { + val (testSet, coverage) = if (coverageMatcher is DoNotCalculate) { MethodResult(executions(utMethod, mockStrategy, additionalDependenciesClassPath), Coverage()) } else { walk(utMethod, mockStrategy, additionalDependenciesClassPath) } - testCase.summarize(searchDirectory) - val valueTestCase = testCase.toValueTestCase(jimpleBody(utMethod)) + testSet.summarize(searchDirectory) + val valueTestCase = testSet.toValueTestCase() - assertTrue(testCase.errors.isEmpty()) { + assertTrue(testSet.errors.isEmpty()) { "We have errors: ${ - testCase.errors.entries.map { "${it.value}: ${it.key}" }.prettify() + testSet.errors.entries.map { "${it.value}: ${it.key}" }.prettify() }" } @@ -2375,7 +2374,7 @@ abstract class UtValueTestCaseChecker( "Coverage matcher '$coverageMatcher' fails for $coverage (at least: ${coverage.toAtLeast()})" } - processTestCase(testCase) + processTestCase(testSet) } } @@ -2477,21 +2476,20 @@ abstract class UtValueTestCaseChecker( mockStrategy: MockStrategyApi, additionalDependenciesClassPath: String = "" ): MethodResult { - val testCase = executions(method, mockStrategy, additionalDependenciesClassPath) - val jimpleBody = jimpleBody(method) + val testSet = executions(method, mockStrategy, additionalDependenciesClassPath) val methodCoverage = methodCoverage( method, - testCase.toValueTestCase(jimpleBody).executions, + testSet.toValueTestCase().executions, buildDir.toString() + File.pathSeparator + additionalDependenciesClassPath ) - return MethodResult(testCase, methodCoverage) + return MethodResult(testSet, methodCoverage) } fun executions( method: UtMethod<*>, mockStrategy: MockStrategyApi, additionalDependenciesClassPath: String - ): UtTestCase { + ): UtMethodTestSet { TestSpecificTestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path")) return TestSpecificTestCaseGenerator.generate(method, mockStrategy) } @@ -2500,7 +2498,7 @@ abstract class UtValueTestCaseChecker( method: UtMethod<*>, mockStrategy: MockStrategyApi, additionalDependencies: Array> = emptyArray() - ): UtTestCase { + ): UtMethodTestSet { val additionalDependenciesClassPath = computeAdditionalDependenciesClasspathAndBuildDir(method, additionalDependencies) TestSpecificTestCaseGenerator.init(buildDir, additionalDependenciesClassPath, System.getProperty("java.class.path")) @@ -2535,7 +2533,7 @@ abstract class UtValueTestCaseChecker( val substituteStatics: Boolean ) - data class MethodResult(val testCase: UtTestCase, val coverage: Coverage) + data class MethodResult(val testSet: UtMethodTestSet, val coverage: Coverage) } @Suppress("UNCHECKED_CAST") diff --git a/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt b/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt index 7b46f4a2ea..d74a2d62ea 100644 --- a/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt +++ b/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt @@ -12,7 +12,7 @@ import org.utbot.framework.plugin.api.MockFramework import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.framework.plugin.api.util.description @@ -26,7 +26,7 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram fun runClassesCodeGenerationTests(classesStages: List) { val pipelines = classesStages.map { - with(it) { ClassPipeline(StageContext(testClass, testCases, testCases.size), check) } + with(it) { ClassPipeline(StageContext(testClass, testSets, testSets.size), check) } } if (pipelines.isEmpty()) return @@ -69,11 +69,11 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram private fun processCodeGenerationStage(classPipeline: ClassPipeline) { with(classPipeline.stageContext) { val information = StageExecutionInformation(CodeGeneration) - val testCases = data as List + val testSets = data as List val codegenLanguage = testFrameworkConfiguration.codegenLanguage - val testClass = callToCodeGenerator(testCases, classUnderTest) + val testClass = callToCodeGenerator(testSets, classUnderTest) // actual number of the tests in the generated testClass val generatedMethodsCount = testClass @@ -87,7 +87,7 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram } } // expected number of the tests in the generated testClass - val expectedNumberOfGeneratedMethods = testCases.sumOf { it.executions.size } + val expectedNumberOfGeneratedMethods = testSets.sumOf { it.executions.size } // check for error in the generated file runCatching { @@ -200,7 +200,7 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram } private fun callToCodeGenerator( - testCases: List, + testSets: List, classUnderTest: KClass<*> ): String { val params = mutableMapOf, List>() @@ -224,7 +224,7 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram } val testClassCustomName = "${classUnderTest.java.simpleName}GeneratedTest" - return codeGenerator.generateAsString(testCases, testClassCustomName) + return codeGenerator.generateAsString(testSets, testClassCustomName) } private fun checkPipelinesResults(classesPipelines: List) { @@ -236,11 +236,11 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram @Suppress("unused") internal fun checkResults( targetClasses: List>, - testCases: List = listOf(), + testSets: List = listOf(), lastStage: Stage = TestExecution, vararg checks: StageStatusCheck ) { - val results = executeTestGenerationPipeline(targetClasses, testCases, lastStage) + val results = executeTestGenerationPipeline(targetClasses, testSets, lastStage) processResults(results, results.map { it.classUnderTest to checks.toList() }) } @@ -273,7 +273,7 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram private fun executeTestGenerationPipeline( targetClasses: List>, - testCases: List, + testSets: List, lastStage: Stage = TestExecution ): List = targetClasses.map { val buildDir = FileUtil.isolateClassFiles(it).toPath() @@ -284,7 +284,7 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram val pipelineStages = runPipelinesStages( listOf( ClassPipeline( - StageContext(it, testCases, testCases.size), + StageContext(it, testSets, testSets.size), StageStatusCheck(lastStage = lastStage, status = SUCCESS) ) ) @@ -413,7 +413,7 @@ data class StageContext( data class ClassStages( val testClass: KClass<*>, val check: StageStatusCheck, - val testCases: List = emptyList() + val testSets: List = emptyList() ) data class ClassPipeline(var stageContext: StageContext, val check: StageStatusCheck) \ No newline at end of file diff --git a/utbot-framework/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt b/utbot-framework/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt index 7c200508d5..2c45672ae9 100644 --- a/utbot-framework/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt +++ b/utbot-framework/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt @@ -6,7 +6,7 @@ import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtImplicitlyThrownException import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtPrimitiveModel -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.junit.Test import org.mockito.Mockito @@ -15,7 +15,7 @@ class SarifReportTest { @Test fun testNonEmptyReport() { val actualReport = SarifReport( - testCases = listOf(), + testSets = listOf(), generatedTestsCode = "", sourceFindingEmpty ).createReport() @@ -26,7 +26,7 @@ class SarifReportTest { @Test fun testNoUncheckedExceptions() { val sarif = SarifReport( - testCases = listOf(testCase), + testSets = listOf(testSet), generatedTestsCode = "", sourceFindingEmpty ).createReport().toSarif() @@ -50,13 +50,13 @@ class SarifReportTest { ) Mockito.`when`(mockUtExecutionAIOBE.stateBefore.parameters).thenReturn(listOf()) - val testCases = listOf( - UtTestCase(mockUtMethod, listOf(mockUtExecutionNPE)), - UtTestCase(mockUtMethod, listOf(mockUtExecutionAIOBE)) + val testSets = listOf( + UtMethodTestSet(mockUtMethod, listOf(mockUtExecutionNPE)), + UtMethodTestSet(mockUtMethod, listOf(mockUtExecutionAIOBE)) ) val report = SarifReport( - testCases = testCases, + testSets = testSets, generatedTestsCode = "", sourceFindingEmpty ).createReport().toSarif() @@ -193,13 +193,13 @@ class SarifReportTest { val mockUtExecution = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) Mockito.`when`(mockUtExecution.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) - val testCases = listOf( - UtTestCase(mockUtMethod, listOf(mockUtExecution)), - UtTestCase(mockUtMethod, listOf(mockUtExecution)) // duplicate + val testSets = listOf( + UtMethodTestSet(mockUtMethod, listOf(mockUtExecution)), + UtMethodTestSet(mockUtMethod, listOf(mockUtExecution)) // duplicate ) val report = SarifReport( - testCases = testCases, + testSets = testSets, generatedTestsCode = "", sourceFindingMain ).createReport().toSarif() @@ -218,13 +218,13 @@ class SarifReportTest { Mockito.`when`(mockUtExecution1.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) Mockito.`when`(mockUtExecution2.result).thenReturn(UtImplicitlyThrownException(ArithmeticException(), false)) - val testCases = listOf( - UtTestCase(mockUtMethod, listOf(mockUtExecution1)), - UtTestCase(mockUtMethod, listOf(mockUtExecution2)) // not a duplicate + val testSets = listOf( + UtMethodTestSet(mockUtMethod, listOf(mockUtExecution1)), + UtMethodTestSet(mockUtMethod, listOf(mockUtExecution2)) // not a duplicate ) val report = SarifReport( - testCases = testCases, + testSets = testSets, generatedTestsCode = "", sourceFindingMain ).createReport().toSarif() @@ -247,13 +247,13 @@ class SarifReportTest { Mockito.`when`(mockUtExecution1.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(11) Mockito.`when`(mockUtExecution2.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(22) - val testCases = listOf( - UtTestCase(mockUtMethod, listOf(mockUtExecution1)), - UtTestCase(mockUtMethod, listOf(mockUtExecution2)) // not a duplicate + val testSets = listOf( + UtMethodTestSet(mockUtMethod, listOf(mockUtExecution1)), + UtMethodTestSet(mockUtMethod, listOf(mockUtExecution2)) // not a duplicate ) val report = SarifReport( - testCases = testCases, + testSets = testSets, generatedTestsCode = "", sourceFindingMain ).createReport().toSarif() @@ -281,13 +281,13 @@ class SarifReportTest { Mockito.`when`(mockNPE1.stackTrace).thenReturn(arrayOf(stackTraceElement1)) Mockito.`when`(mockNPE2.stackTrace).thenReturn(arrayOf(stackTraceElement1, stackTraceElement2)) - val testCases = listOf( - UtTestCase(mockUtMethod, listOf(mockUtExecution1)), - UtTestCase(mockUtMethod, listOf(mockUtExecution2)) // duplicate with a longer stack trace + val testSets = listOf( + UtMethodTestSet(mockUtMethod, listOf(mockUtExecution1)), + UtMethodTestSet(mockUtMethod, listOf(mockUtExecution2)) // duplicate with a longer stack trace ) val report = SarifReport( - testCases = testCases, + testSets = testSets, generatedTestsCode = "", sourceFindingMain ).createReport().toSarif() @@ -302,7 +302,7 @@ class SarifReportTest { private val mockUtExecution = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - private val testCase = UtTestCase(mockUtMethod, listOf(mockUtExecution)) + private val testSet = UtMethodTestSet(mockUtMethod, listOf(mockUtExecution)) private fun mockUtMethodNames() { Mockito.`when`(mockUtMethod.callable.name).thenReturn("main") @@ -343,8 +343,8 @@ class SarifReportTest { """.trimIndent() private val sarifReportMain = - SarifReport(listOf(testCase), generatedTestsCodeMain, sourceFindingMain) + SarifReport(listOf(testSet), generatedTestsCodeMain, sourceFindingMain) private val sarifReportPrivateMain = - SarifReport(listOf(testCase), generatedTestsCodePrivateMain, sourceFindingMain) + SarifReport(listOf(testSet), generatedTestsCodePrivateMain, sourceFindingMain) } \ No newline at end of file diff --git a/utbot-fuzzers/src/main/java/org/utbot/fuzzer/baseline/generator/Generator.java b/utbot-fuzzers/src/main/java/org/utbot/fuzzer/baseline/generator/Generator.java index c0770653e7..86cd17e7e4 100644 --- a/utbot-fuzzers/src/main/java/org/utbot/fuzzer/baseline/generator/Generator.java +++ b/utbot-fuzzers/src/main/java/org/utbot/fuzzer/baseline/generator/Generator.java @@ -2,7 +2,7 @@ import org.utbot.framework.plugin.api.UtMethod; import org.utbot.framework.plugin.api.UtValueExecution; -import org.utbot.framework.plugin.api.UtValueTestCase; +import org.utbot.framework.plugin.api.UtMethodValueTestSet; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; @@ -38,11 +38,11 @@ private static boolean isSameMethod(UtMethod utMethod, Method method) { return utJavaMethod.equals(method); } - public static UtValueTestCase generateTests(UtMethod method) throws IllegalAccessException, InstantiationException { + public static UtMethodValueTestSet generateTests(UtMethod method) throws IllegalAccessException, InstantiationException { KClass kClass = method.getClazz(); Class clazz = JvmClassMappingKt.getJavaClass(kClass); // TODO: newInstance() is deprecated, need to create an instance in another way Object object = clazz.newInstance(); - return new UtValueTestCase<>(method, executions(method, clazz, object), null, emptyMap()); + return new UtMethodValueTestSet<>(method, executions(method, clazz, object), emptyMap()); } } diff --git a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/ObsoleteTestCaseGenerator.kt b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/ObsoleteTestCaseGenerator.kt index 4076e712ac..cbc24439c4 100644 --- a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/ObsoleteTestCaseGenerator.kt +++ b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/ObsoleteTestCaseGenerator.kt @@ -2,8 +2,8 @@ package org.utbot.fuzzer import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtValueTestCase +import org.utbot.framework.plugin.api.UtMethodValueTestSet interface ObsoleteTestCaseGenerator { - fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtValueTestCase<*> + fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtMethodValueTestSet<*> } \ No newline at end of file diff --git a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/baseline/BaselineFuzzer.kt b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/baseline/BaselineFuzzer.kt index 5903441c8d..402941bf2b 100644 --- a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/baseline/BaselineFuzzer.kt +++ b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/baseline/BaselineFuzzer.kt @@ -4,14 +4,14 @@ import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtConcreteValue import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtValueExecution -import org.utbot.framework.plugin.api.UtValueTestCase +import org.utbot.framework.plugin.api.UtMethodValueTestSet import org.utbot.fuzzer.ObsoleteTestCaseGenerator import org.utbot.fuzzer.baseline.generator.Generator import kotlin.Result.Companion.failure import kotlin.Result.Companion.success object BaselineFuzzer : ObsoleteTestCaseGenerator { - override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtValueTestCase<*> = + override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtMethodValueTestSet<*> = Generator.generateTests(method) } diff --git a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/primitive/PrimitiveFuzzer.kt b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/primitive/PrimitiveFuzzer.kt index c84ba32c2b..8e987f7d5c 100644 --- a/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/primitive/PrimitiveFuzzer.kt +++ b/utbot-fuzzers/src/main/kotlin/org/utbot/fuzzer/primitive/PrimitiveFuzzer.kt @@ -4,7 +4,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtConcreteValue import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtValueExecution -import org.utbot.framework.plugin.api.UtValueTestCase +import org.utbot.framework.plugin.api.UtMethodValueTestSet import org.utbot.fuzzer.ObsoleteTestCaseGenerator import kotlin.Result.Companion.success import kotlin.reflect.KCallable @@ -13,8 +13,8 @@ import kotlin.reflect.KParameter.Kind import kotlin.reflect.KType object PrimitiveFuzzer : ObsoleteTestCaseGenerator { - override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtValueTestCase<*> = - UtValueTestCase(method, executions(method.callable)) + override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtMethodValueTestSet<*> = + UtMethodValueTestSet(method, executions(method.callable)) } private fun executions(method: KCallable) = listOf(execution(method)) diff --git a/utbot-fuzzers/src/test/kotlin/org/utbot/framework/plugin/api/FuzzerTestCaseGeneratorTest.kt b/utbot-fuzzers/src/test/kotlin/org/utbot/framework/plugin/api/FuzzerTestCaseGeneratorTest.kt index 2a976b18e0..7ed6c46ab1 100644 --- a/utbot-fuzzers/src/test/kotlin/org/utbot/framework/plugin/api/FuzzerTestCaseGeneratorTest.kt +++ b/utbot-fuzzers/src/test/kotlin/org/utbot/framework/plugin/api/FuzzerTestCaseGeneratorTest.kt @@ -15,8 +15,8 @@ internal class FuzzerTestCaseGeneratorTest { @ParameterizedTest @MethodSource("manyMethods") fun testManyMethods(method: KFunction<*>, returnType: KClass<*>, vararg paramTypes: KClass<*>) { - val testCase = generate(method) - testCase.executions.forEach { execution -> + val valueTestSet = generate(method) + valueTestSet.executions.forEach { execution -> assertEquals(paramTypes.toList(), execution.stateBefore.params.map { it.type }) { "$method" } assertTrue(execution.returnValue.isSuccess) { "$method" } val value = execution.returnValue.getOrNull() diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt index 010ee21ea7..6e2f72e203 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt @@ -59,7 +59,7 @@ import org.utbot.framework.codegen.model.TestsCodeWithTestReport import org.utbot.framework.codegen.model.constructor.tree.TestsGenerationReport import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.intellij.plugin.generator.CodeGenerationController.Target.EDT_LATER @@ -88,14 +88,14 @@ import kotlin.reflect.full.functions object CodeGenerationController { private enum class Target { THREAD_POOL, READ_ACTION, WRITE_ACTION, EDT_LATER } - fun generateTests(model: GenerateTestsModel, testCasesByClass: Map>) { + fun generateTests(model: GenerateTestsModel, testSetsByClass: Map>) { val baseTestDirectory = model.testSourceRoot?.toPsiDirectory(model.project) ?: return val allTestPackages = getPackageDirectories(baseTestDirectory) - val latch = CountDownLatch(testCasesByClass.size) + val latch = CountDownLatch(testSetsByClass.size) - for (srcClass in testCasesByClass.keys) { - val testCases = testCasesByClass[srcClass] ?: continue + for (srcClass in testSetsByClass.keys) { + val testSets = testSetsByClass[srcClass] ?: continue try { val classPackageName = if (model.testPackageName.isNullOrEmpty()) srcClass.containingFile.containingDirectory.getPackage()?.qualifiedName else model.testPackageName @@ -104,7 +104,7 @@ object CodeGenerationController { val file = testClass.containingFile runWriteCommandAction(model.project, "Generate tests with UtBot", null, { try { - generateCodeAndSaveReports(testClass, file, testCases, model, latch) + generateCodeAndSaveReports(testClass, file, testSets, model, latch) } catch (e: IncorrectOperationException) { showCreatingClassError(model.project, createTestClassName(srcClass)) } @@ -240,7 +240,7 @@ object CodeGenerationController { private fun generateCodeAndSaveReports( testClass: PsiClass, file: PsiFile, - testCases: List, + testSets: List, model: GenerateTestsModel, reportsCountDown: CountDownLatch, ) { @@ -249,7 +249,7 @@ object CodeGenerationController { val mockito = model.mockFramework val staticsMocking = model.staticsMocking - val classUnderTest = testCases.first().method.clazz + val classUnderTest = testSets.first().method.clazz val params = findMethodParams(classUnderTest, selectedMethods) @@ -275,7 +275,7 @@ object CodeGenerationController { //TODO: Use PsiDocumentManager.getInstance(model.project).getDocument(file) // if we don't want to open _all_ new files with tests in editor one-by-one run(THREAD_POOL) { - val testsCodeWithTestReport = codeGenerator.generateAsStringWithTestReport(testCases) + val testsCodeWithTestReport = codeGenerator.generateAsStringWithTestReport(testSets) val generatedTestsCode = testsCodeWithTestReport.generatedCode run(EDT_LATER) { run(WRITE_ACTION) { @@ -304,7 +304,7 @@ object CodeGenerationController { // creating and saving reports saveSarifAndTestReports( testClassUpdated, - testCases, + testSets, model, testsCodeWithTestReportFormatted, reportsCountDown @@ -346,7 +346,7 @@ object CodeGenerationController { private fun saveSarifAndTestReports( testClass: PsiClass, - testCases: List, + testSets: List, model: GenerateTestsModel, testsCodeWithTestReport: TestsCodeWithTestReport, reportsCountDown: CountDownLatch @@ -358,7 +358,7 @@ object CodeGenerationController { // saving sarif report val sourceFinding = SourceFindingStrategyIdea(testClass) executeCommand(testClass.project, "Saving Sarif report") { - SarifReportIdea.createAndSave(model, testCases, generatedTestsCode, sourceFinding) + SarifReportIdea.createAndSave(model, testSets, generatedTestsCode, sourceFinding) } } catch (e: Exception) { showErrorDialogLater( diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt index 5bde74bc1b..ab357d3aef 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt @@ -26,7 +26,7 @@ import org.utbot.framework.UtSettings import org.utbot.framework.codegen.ParametrizedTestSource import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.withSubstitutionCondition import org.utbot.framework.plugin.api.util.withUtContext @@ -125,7 +125,7 @@ object UtTestsDialogProcessor { val classLoader = urlClassLoader(listOf(buildDir) + classpathList) val context = UtContext(classLoader) - val testCasesByClass = mutableMapOf>() + val testSetsByClass = mutableMapOf>() var processedClasses = 0 val totalClasses = model.srcClasses.size @@ -199,7 +199,7 @@ object UtTestsDialogProcessor { title = "Failed to generate unit tests for class $className" ) } else { - testCasesByClass[srcClass] = notEmptyCases + testSetsByClass[srcClass] = notEmptyCases } forceMockListener?.run { @@ -222,7 +222,7 @@ object UtTestsDialogProcessor { invokeLater { withUtContext(context) { - generateTests(model, testCasesByClass) + generateTests(model, testSetsByClass) } } } diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt index 800a028714..1d84554bf6 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt @@ -1,7 +1,7 @@ package org.utbot.intellij.plugin.sarif import org.utbot.common.PathUtil.classFqnToPath -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.intellij.plugin.ui.utils.getOrCreateSarifReportsPath import org.utbot.sarif.SarifReport import com.intellij.openapi.vfs.VfsUtil @@ -15,12 +15,12 @@ object SarifReportIdea { */ fun createAndSave( model: GenerateTestsModel, - testCases: List, + testSets: List, generatedTestsCode: String, sourceFinding: SourceFindingStrategyIdea ) { // building the path to the report file - val classFqn = testCases.firstOrNull()?.method?.clazz?.qualifiedName ?: return + val classFqn = testSets.firstOrNull()?.method?.clazz?.qualifiedName ?: return val sarifReportsPath = model.testModule.getOrCreateSarifReportsPath(model.testSourceRoot) val reportFilePath = sarifReportsPath.resolve("${classFqnToPath(classFqn)}Report.sarif") @@ -30,7 +30,7 @@ object SarifReportIdea { // creating & saving sarif report reportFilePath .toFile() - .writeText(SarifReport(testCases, generatedTestsCode, sourceFinding).createReport()) + .writeText(SarifReport(testSets, generatedTestsCode, sourceFinding).createReport()) } } 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 0778a303c4..3075ca38f7 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 @@ -33,8 +33,7 @@ import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.UtError import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtMethod -import org.utbot.framework.plugin.api.UtTestCase -import org.utbot.framework.plugin.api.UtValueTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass @@ -43,9 +42,6 @@ import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.instrumentation.ConcreteExecutor import org.utbot.instrumentation.ConcreteExecutorPool import org.utbot.instrumentation.Settings -import org.utbot.instrumentation.execute -import org.utbot.instrumentation.instrumentation.coverage.CoverageInstrumentation -import org.utbot.instrumentation.util.StaticEnvironment import org.utbot.instrumentation.warmup.Warmup import java.io.File import java.lang.reflect.Method @@ -179,7 +175,7 @@ fun runGeneration( - val testCases: MutableList = mutableListOf() + val testSets: MutableList = mutableListOf() val currentContext = utContext val timeBudgetMs = timeLimitSec * 1000 @@ -341,7 +337,7 @@ fun runGeneration( statsForMethod.testsGeneratedCount++ //TODO: it is a strange hack to create fake test case for one [UtResult] - testCases.add(UtTestCase(method, listOf(result))) + testSets.add(UtMethodTestSet(method, listOf(result))) } catch (e: Throwable) { //Here we need isolation logger.error(e) { "Code generation failed" } @@ -394,7 +390,7 @@ fun runGeneration( cancellator.cancel() logger.info().bracket("Flushing tests for [${cut.simpleName}] on disk") { - writeTestClass(cut, codeGenerator.generateAsString(testCases)) + writeTestClass(cut, codeGenerator.generateAsString(testSets)) } //write classes } @@ -423,21 +419,6 @@ fun runGeneration( statsForClass } -private fun ConcreteExecutor, CoverageInstrumentation>.executeTestCase(testCase: UtValueTestCase<*>) { - testCase.executions.forEach { - val method = testCase.method.callable - for (execution in testCase.executions) { - val args = (listOfNotNull(execution.stateBefore.caller) + execution.stateBefore.params) - .map { it.value }.toMutableList() - val staticEnvironment = StaticEnvironment( - execution.stateBefore.statics.map { it.key to it.value.value } - ) - this.execute(method, args.toTypedArray(), parameters = staticEnvironment) - } - } - -} - private fun prepareClass(kotlinClass: KClass<*>, methodNameFilter: String?): List> { //1. all methods and properties from cut val kotlin2java = kotlinClass.declaredMembers @@ -476,10 +457,10 @@ private fun prepareClass(kotlinClass: KClass<*>, methodNameFilter: String?): Lis } } -fun writeTestClass(cut: ClassUnderTest, testCasesAsString: String) { - logger.info { "File size for ${cut.testClassSimpleName}: ${FileUtils.byteCountToDisplaySize(testCasesAsString.length.toLong())}" } +fun writeTestClass(cut: ClassUnderTest, testSetsAsString: String) { + logger.info { "File size for ${cut.testClassSimpleName}: ${FileUtils.byteCountToDisplaySize(testSetsAsString.length.toLong())}" } cut.generatedTestFile.parentFile.mkdirs() - cut.generatedTestFile.writeText(testCasesAsString, charset) + cut.generatedTestFile.writeText(testSetsAsString, charset) } private inline fun KCallable<*>.withAccessibility(block: () -> R): R { diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index 1cee8edecb..7dcc3df548 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -97,12 +97,12 @@ open class SummaryTestCaseGeneratorTest( checkNpeInNestedNotPrivateMethods = true } val utMethod = UtMethod.from(method) - val testCase = executionsModel(utMethod, mockStrategy) - testCase.summarize(searchDirectory) + val testSet = executionsModel(utMethod, mockStrategy) + testSet.summarize(searchDirectory) - testCase.executions.checkMatchersWithTextSummary(summaryKeys) - testCase.executions.checkMatchersWithMethodNames(methodNames) - testCase.executions.checkMatchersWithDisplayNames(displayNames) + testSet.executions.checkMatchersWithTextSummary(summaryKeys) + testSet.executions.checkMatchersWithMethodNames(methodNames) + testSet.executions.checkMatchersWithDisplayNames(displayNames) } /** @@ -159,7 +159,7 @@ open class SummaryTestCaseGeneratorTest( } private fun summaries(executions: List): String { - var result = ""; + var result = "" executions.forEach { result += it.summary?.joinToString(separator = "", postfix = "\n") } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt index fb473101e5..cab135ea21 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt @@ -5,7 +5,7 @@ import org.utbot.framework.UtSettings import org.utbot.framework.plugin.api.UtClusterInfo import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtExecutionCluster -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter import org.utbot.summary.SummarySentenceConstants.NEW_LINE import org.utbot.summary.UtSummarySettings.GENERATE_CLUSTER_COMMENTS @@ -27,7 +27,7 @@ import soot.SootMethod private val logger = KotlinLogging.logger {} -fun UtTestCase.summarize(sourceFile: File?, searchDirectory: Path = Paths.get("")): UtTestCase { +fun UtMethodTestSet.summarize(sourceFile: File?, searchDirectory: Path = Paths.get("")): UtMethodTestSet { if (!UtSettings.enableMachineLearningModule) return this return try { @@ -50,7 +50,7 @@ fun UtTestCase.summarize(sourceFile: File?, searchDirectory: Path = Paths.get("" } } -fun UtTestCase.summarize(searchDirectory: Path): UtTestCase = +fun UtMethodTestSet.summarize(searchDirectory: Path): UtMethodTestSet = this.summarize(Instrumenter.computeSourceFileByClass(this.method.clazz.java, searchDirectory), searchDirectory) @@ -58,31 +58,31 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List { + fun summary(testSet: UtMethodTestSet): List { val namesCounter = mutableMapOf() - if (testCase.executions.isEmpty()) { + if (testSet.executions.isEmpty()) { logger.info { "No execution traces found in test case " + - "for method ${testCase.method.clazz.qualifiedName}, " + "${testCase.jimpleBody}" + "for method ${testSet.method.clazz.qualifiedName}, " + "${testSet.jimpleBody}" } - return listOf(UtExecutionCluster(UtClusterInfo(), testCase.executions)) + return listOf(UtExecutionCluster(UtClusterInfo(), testSet.executions)) } // init - val sootToAST = sootToAST(testCase) - val jimpleBody = testCase.jimpleBody + val sootToAST = sootToAST(testSet) + val jimpleBody = testSet.jimpleBody val updatedExecutions = mutableListOf() val clustersToReturn = mutableListOf() // TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428 - val executionsProducedByFuzzer = getExecutionsWithEmptyPath(testCase) + val executionsProducedByFuzzer = getExecutionsWithEmptyPath(testSet) if (executionsProducedByFuzzer.isNotEmpty()) { executionsProducedByFuzzer.forEach { logger.info { "The path for test ${it.testMethodName} " + - "for method ${testCase.method.clazz.qualifiedName} is empty and summaries could not be generated." + "for method ${testSet.method.clazz.qualifiedName} is empty and summaries could not be generated." } } @@ -97,7 +97,7 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List? { val sootToAST = mutableMapOf() - val jimpleBody = testCase.jimpleBody + val jimpleBody = testSet.jimpleBody if (jimpleBody == null) { logger.info { "No jimple body of method under test" } return null } val methodUnderTestAST = sourceFile?.let { - SourceCodeParser(it, testCase).methodAST + SourceCodeParser(it, testSet).methodAST } if (methodUnderTestAST == null) { @@ -196,15 +196,15 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List 0) { logger.info { "Recursive function, max recursion: $maxDepth" } return } - var diversity = percentageDiverseExecutions(testCase.executions) + var diversity = percentageDiverseExecutions(testSet.executions) if (diversity >= 50) { logger.info { "Diversity execution path percentage: $diversity" } return @@ -212,8 +212,8 @@ private fun makeDiverseExecutions(testCase: UtTestCase) { for (depth in 1..2) { logger.info { "Depth to add: $depth" } - stepsUpToDepth(testCase.executions, depth) - diversity = percentageDiverseExecutions(testCase.executions) + stepsUpToDepth(testSet.executions, depth) + diversity = percentageDiverseExecutions(testSet.executions) if (diversity >= 50) { logger.info { "Diversity execution path percentage: $diversity" } @@ -222,8 +222,8 @@ private fun makeDiverseExecutions(testCase: UtTestCase) { } } -private fun invokeDescriptions(testCase: UtTestCase, seachDirectory: Path): List { - val sootInvokes = testCase.executions.flatMap { it.path.invokeJimpleMethods() }.toSet() +private fun invokeDescriptions(testSet: UtMethodTestSet, seachDirectory: Path): List { + val sootInvokes = testSet.executions.flatMap { it.path.invokeJimpleMethods() }.toSet() return sootInvokes //TODO(SAT-1170) .filterNot { "\$lambda" in it.declaringClass.name } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt index c8ea78c86e..2b5df3ca25 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt @@ -8,7 +8,7 @@ import org.utbot.framework.plugin.api.UtExecutionSuccess import org.utbot.framework.plugin.api.UtExplicitlyThrownException import org.utbot.framework.plugin.api.UtImplicitlyThrownException import org.utbot.framework.plugin.api.UtOverflowFailure -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.UtTimeoutException import org.utbot.framework.plugin.api.util.isCheckedException import org.utbot.summary.UtSummarySettings.MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING @@ -18,8 +18,8 @@ import org.utbot.summary.tag.TraceTag import org.utbot.summary.tag.TraceTagWithoutExecution class TagGenerator { - fun testCaseToTags(testCase: UtTestCase): List { - val clusteredExecutions = toClusterExecutions(testCase) + fun testSetToTags(testSet: UtMethodTestSet): List { + val clusteredExecutions = toClusterExecutions(testSet) val traceTagClusters = mutableListOf() val numberOfSuccessfulClusters = clusteredExecutions.filterIsInstance().size @@ -94,10 +94,10 @@ private fun generateExecutionTags(executions: List, splitSteps: Spl * * @return clustered executions */ -private fun toClusterExecutions(testCase: UtTestCase): List { - val methodExecutions = testCase.executions.filter { it.path.isNotEmpty() } // TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428 +private fun toClusterExecutions(testSet: UtMethodTestSet): List { + val methodExecutions = testSet.executions.filter { it.path.isNotEmpty() } // TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428 val clusters = mutableListOf() - val commentPostfix = "for method ${testCase.method.displayName}" + val commentPostfix = "for method ${testSet.method.displayName}" val grouped = methodExecutions.groupBy { it.result.clusterKind() } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/SourceCodeParser.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/SourceCodeParser.kt index 89f1407b21..477e72a973 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/SourceCodeParser.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/SourceCodeParser.kt @@ -7,9 +7,8 @@ import com.github.javaparser.ast.Node import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration import com.github.javaparser.ast.body.MethodDeclaration import com.github.javaparser.ast.body.TypeDeclaration -import org.utbot.framework.plugin.api.UtTestCase +import org.utbot.framework.plugin.api.UtMethodTestSet import java.io.File -import java.nio.file.Path import kotlin.math.abs import soot.SootMethod @@ -22,13 +21,13 @@ class SourceCodeParser { private val cu: ParseResult var methodAST: MethodDeclaration? = null - constructor(sourceFile: File, testCase: UtTestCase) { + constructor(sourceFile: File, testSet: UtMethodTestSet) { val parser = JavaParser() cu = parser.parse(sourceFile) - val className = testCase.method.clazz.simpleName - val methodName = testCase.method.callable.name + val className = testSet.method.clazz.simpleName + val methodName = testSet.method.callable.name - val lineNumbers = testCase.jimpleBody?.units?.map { it.javaSourceStartLineNumber } + val lineNumbers = testSet.jimpleBody?.units?.map { it.javaSourceStartLineNumber } val maxLineNumber = lineNumbers?.maxOrNull() if (className != null && maxLineNumber != null) findMethod(className, methodName, maxLineNumber) } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/clustering/MatrixUniqueness.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/clustering/MatrixUniqueness.kt index c67d9d0f55..3ac3806925 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/clustering/MatrixUniqueness.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/clustering/MatrixUniqueness.kt @@ -2,20 +2,16 @@ package org.utbot.summary.clustering import org.utbot.framework.plugin.api.Step import org.utbot.framework.plugin.api.UtExecution -import org.utbot.framework.plugin.api.UtTestCase import org.utbot.summary.UtSummarySettings import smile.clustering.dbscan -class MatrixUniqueness { +class MatrixUniqueness(executions: List) { - private var methodExecutions: List + private var methodExecutions: List = executions private val allSteps = mutableListOf() private val matrix: List - constructor(testCase: UtTestCase) : this(testCase.executions) - - constructor (executions: List) { - this.methodExecutions = executions + init { executions.forEach { it.path.forEach { step -> if (step !in allSteps) allSteps.add(step)