Skip to content

Commit ac0fd7f

Browse files
Enlarge the set of cases when we try to create parametrized tests (#678)
1 parent ea2b0af commit ac0fd7f

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ object UtSettings {
212212
/**
213213
* Activate or deactivate substituting static fields values set in static initializer
214214
* with symbolic variable to try to set them another value than in initializer.
215-
*
216-
* We should not try to substitute in parametrized tests, for example
217215
*/
218216
var substituteStaticsWithSymbolicVariable by getBooleanProperty(true)
219217

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.utbot.framework.UtSettings
66
* Runs [block] with [UtSettings.substituteStaticsWithSymbolicVariable] value
77
* modified in accordance with given [condition].
88
*/
9-
inline fun <T> withSubstitutionCondition(condition: Boolean, block: () -> T) {
9+
inline fun <T> withStaticsSubstitutionRequired(condition: Boolean, block: () -> T) {
1010
val standardSubstitutionSetting = UtSettings.substituteStaticsWithSymbolicVariable
1111
UtSettings.substituteStaticsWithSymbolicVariable = standardSubstitutionSetting && condition
1212
try {

utbot-framework/src/main/kotlin/org/utbot/engine/Mocks.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ class Mocker(
168168
fun shouldMock(
169169
type: RefType,
170170
mockInfo: UtMockInfo,
171-
): Boolean = checkIfShouldMock(type, mockInfo).also { if (it) mockListenerController?.onShouldMock(strategy, mockInfo) }
171+
): Boolean = checkIfShouldMock(type, mockInfo).also {
172+
//[utbotSuperClasses] are not involved in code generation, so
173+
//we shouldn't listen events that such mocks happened
174+
if (it && type.id !in utbotSuperClasses.map { it.id }) {
175+
mockListenerController?.onShouldMock(strategy, mockInfo)
176+
}
177+
}
172178

173179
private fun checkIfShouldMock(
174180
type: RefType,

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.utbot.framework.plugin.api.TestCaseGenerator
3333
import org.utbot.framework.plugin.api.UtMethod
3434
import org.utbot.framework.plugin.api.UtMethodTestSet
3535
import org.utbot.framework.plugin.api.util.UtContext
36-
import org.utbot.framework.plugin.api.util.withSubstitutionCondition
36+
import org.utbot.framework.plugin.api.util.withStaticsSubstitutionRequired
3737
import org.utbot.framework.plugin.api.util.withUtContext
3838
import org.utbot.intellij.plugin.generator.CodeGenerationController.generateTests
3939
import org.utbot.intellij.plugin.models.GenerateTestsModel
@@ -170,17 +170,14 @@ object UtTestsDialogProcessor {
170170
indicator.fraction = indicator.fraction.coerceAtLeast(0.9 * processedClasses / totalClasses)
171171
}
172172

173-
//we should not substitute statics for parametrized tests
174-
val shouldSubstituteStatics =
175-
model.parametrizedTestSource != ParametrizedTestSource.PARAMETRIZE
176173
// set timeout for concrete execution and for generated tests
177174
UtSettings.concreteExecutionTimeoutInChildProcess = model.hangingTestsTimeout.timeoutMs
178175

179176
val searchDirectory = ReadAction
180177
.nonBlocking<Path> { project.basePath?.let { Paths.get(it) } ?: Paths.get(srcClass.containingFile.virtualFile.parent.path) }
181178
.executeSynchronously()
182179

183-
withSubstitutionCondition(shouldSubstituteStatics) {
180+
withStaticsSubstitutionRequired(true) {
184181
val mockFrameworkInstalled = model.mockFramework?.isInstalled ?: true
185182

186183
if (!mockFrameworkInstalled) {

0 commit comments

Comments
 (0)