From 94e8f9e20fab4dfefaccf4599ed52c56f54b362f Mon Sep 17 00:00:00 2001 From: Andrey Tarbeev Date: Mon, 3 Oct 2022 20:55:08 +0300 Subject: [PATCH 1/2] Lessen thisInstance creation in parameterized test generation --- .../constructor/tree/CgMethodConstructor.kt | 21 +++---------------- .../framework/codegen/model/tree/CgElement.kt | 2 -- 2 files changed, 3 insertions(+), 20 deletions(-) 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 ba3b5b5a9e..f1b7c39cfc 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 @@ -1368,7 +1368,9 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c substituteStaticFields(statics, isParametrized = true) // build this instance - thisInstance = genericExecution.stateBefore.thisInstance?.let { currentMethodParameters[CgParameterKind.ThisInstance] } + thisInstance = genericExecution.stateBefore.thisInstance?.let { + variableConstructor.getOrCreateVariable(it) + } // build arguments for method under test and parameterized test for (index in genericExecution.stateBefore.parameters.indices) { @@ -1430,20 +1432,6 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c val executableUnderTestParameters = testSet.executableId.executable.parameters return mutableListOf().apply { - // this instance - val thisInstanceModel = genericExecution.stateBefore.thisInstance - if (thisInstanceModel != null) { - val type = wrapTypeIfRequired(thisInstanceModel.classId) - val thisInstance = CgParameterDeclaration( - parameter = declareParameter( - type = type, - name = nameGenerator.variableName(type) - ), - isReferenceType = true - ) - this += thisInstance - currentMethodParameters[CgParameterKind.ThisInstance] = thisInstance.parameter - } // arguments for (index in genericExecution.stateBefore.parameters.indices) { val argumentName = paramNames[executableUnderTest]?.get(index) @@ -1555,9 +1543,6 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c private fun createExecutionArguments(testSet: CgMethodTestSet, execution: UtExecution): List { val arguments = mutableListOf() - execution.stateBefore.thisInstance?.let { - arguments += variableConstructor.getOrCreateVariable(it) - } for ((paramIndex, paramModel) in execution.stateBefore.parameters.withIndex()) { val argumentName = paramNames[testSet.executableId]?.get(paramIndex) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt index 31aca4d64a..05952f59f9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt @@ -745,13 +745,11 @@ data class CgParameterDeclaration( /** * Test method parameter can be one of the following types: - * - this instance for method under test (MUT) * - argument of MUT with a certain index * - result expected from MUT with the given arguments * - exception expected from MUT with the given arguments */ sealed class CgParameterKind { - object ThisInstance : CgParameterKind() data class Argument(val index: Int) : CgParameterKind() data class Statics(val model: UtModel) : CgParameterKind() object ExpectedResult : CgParameterKind() From 339bd6436ba4b0411171a954b8b950435c8fedee Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Fri, 7 Oct 2022 15:25:53 +0300 Subject: [PATCH 2/2] Avoid incorrect configuration --- .../main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt b/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt index 093d9a73bd..a59fa685f3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt @@ -52,6 +52,9 @@ data class TestFrameworkConfiguration( // junit4 doesn't support parametrized tests if (testFramework == Junit4 && parametrizedTestSource == ParametrizedTestSource.PARAMETRIZE) return true + //if we do not use mocks at all, we do not use static mocking too + if (mockStrategy == NO_MOCKS && staticsMocking == MockitoStaticMocking) return true + // if we want to generate mocks for every class but CUT, we must have specified staticsMocking if (mockStrategy == OTHER_CLASSES && staticsMocking == NoStaticMocking) return true