Skip to content

Commit 56bf6ab

Browse files
Lessen thisInstance creation in parameterized test generation (#1065)
* Lessen thisInstance creation in parameterized test generation * Avoid incorrect configuration Co-authored-by: Egor Kulikov <[email protected]>
1 parent cb8474d commit 56bf6ab

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

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

+3-18
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,9 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
13671367
substituteStaticFields(statics, isParametrized = true)
13681368

13691369
// build this instance
1370-
thisInstance = genericExecution.stateBefore.thisInstance?.let { currentMethodParameters[CgParameterKind.ThisInstance] }
1370+
thisInstance = genericExecution.stateBefore.thisInstance?.let {
1371+
variableConstructor.getOrCreateVariable(it)
1372+
}
13711373

13721374
// build arguments for method under test and parameterized test
13731375
for (index in genericExecution.stateBefore.parameters.indices) {
@@ -1429,20 +1431,6 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
14291431
val executableUnderTestParameters = testSet.executableId.executable.parameters
14301432

14311433
return mutableListOf<CgParameterDeclaration>().apply {
1432-
// this instance
1433-
val thisInstanceModel = genericExecution.stateBefore.thisInstance
1434-
if (thisInstanceModel != null) {
1435-
val type = wrapTypeIfRequired(thisInstanceModel.classId)
1436-
val thisInstance = CgParameterDeclaration(
1437-
parameter = declareParameter(
1438-
type = type,
1439-
name = nameGenerator.variableName(type)
1440-
),
1441-
isReferenceType = true
1442-
)
1443-
this += thisInstance
1444-
currentMethodParameters[CgParameterKind.ThisInstance] = thisInstance.parameter
1445-
}
14461434
// arguments
14471435
for (index in genericExecution.stateBefore.parameters.indices) {
14481436
val argumentName = paramNames[executableUnderTest]?.get(index)
@@ -1554,9 +1542,6 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
15541542

15551543
private fun createExecutionArguments(testSet: CgMethodTestSet, execution: UtExecution): List<CgExpression> {
15561544
val arguments = mutableListOf<CgExpression>()
1557-
execution.stateBefore.thisInstance?.let {
1558-
arguments += variableConstructor.getOrCreateVariable(it)
1559-
}
15601545

15611546
for ((paramIndex, paramModel) in execution.stateBefore.parameters.withIndex()) {
15621547
val argumentName = paramNames[testSet.executableId]?.get(paramIndex)

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

-2
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,11 @@ data class CgParameterDeclaration(
745745

746746
/**
747747
* Test method parameter can be one of the following types:
748-
* - this instance for method under test (MUT)
749748
* - argument of MUT with a certain index
750749
* - result expected from MUT with the given arguments
751750
* - exception expected from MUT with the given arguments
752751
*/
753752
sealed class CgParameterKind {
754-
object ThisInstance : CgParameterKind()
755753
data class Argument(val index: Int) : CgParameterKind()
756754
data class Statics(val model: UtModel) : CgParameterKind()
757755
object ExpectedResult : CgParameterKind()

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ data class TestFrameworkConfiguration(
5252
// junit4 doesn't support parametrized tests
5353
if (testFramework == Junit4 && parametrizedTestSource == ParametrizedTestSource.PARAMETRIZE) return true
5454

55+
//if we do not use mocks at all, we do not use static mocking too
56+
if (mockStrategy == NO_MOCKS && staticsMocking == MockitoStaticMocking) return true
57+
5558
// if we want to generate mocks for every class but CUT, we must have specified staticsMocking
5659
if (mockStrategy == OTHER_CLASSES && staticsMocking == NoStaticMocking) return true
5760

0 commit comments

Comments
 (0)