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 2968d75a8f..a5d9db5e42 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 @@ -1537,6 +1537,14 @@ class SpringApplicationContext( exception ) }.orEmpty() + super.getErrors() + + fun getBeansAssignableTo(classId: ClassId): List = beanDefinitions.filter { beanDef -> + // some bean classes may fail to load + runCatching { + val beanClass = ClassId(beanDef.beanTypeName).jClass + classId.jClass.isAssignableFrom(beanClass) + }.getOrElse { false } + } } enum class SpringTestType( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index a213519fc0..d552d32c14 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -40,7 +40,6 @@ import org.utbot.framework.util.calculateSize import org.utbot.framework.util.convertToAssemble import org.utbot.framework.util.graph import org.utbot.framework.util.sootMethod -import org.utbot.framework.plugin.api.SpringSettings.* import org.utbot.fuzzer.* import org.utbot.fuzzing.* import org.utbot.fuzzing.providers.FieldValueProvider @@ -388,9 +387,24 @@ class UtBotSymbolicEngine( val attemptsLimit = UtSettings.fuzzingMaxAttempts val names = graph.body.method.tags.filterIsInstance().firstOrNull()?.names ?: emptyList() var testEmittedByFuzzer = 0 + + if (applicationContext is SpringApplicationContext && + applicationContext.springTestType == SpringTestType.INTEGRATION_TEST && + applicationContext.getBeansAssignableTo(methodUnderTest.classId).isEmpty()) { + val fullConfigDisplayName = (applicationContext.springSettings as? SpringSettings.PresentSpringSettings) + ?.configuration?.fullDisplayName + val errorDescription = "No beans of type ${methodUnderTest.classId.name} are found. " + + "Try choosing different Spring configuration or adding beans to $fullConfigDisplayName" + emit(UtError( + errorDescription, + IllegalStateException(errorDescription) + )) + return@flow + } + val valueProviders = ValueProvider.of(defaultValueProviders(defaultIdGenerator)) .letIf(applicationContext is SpringApplicationContext - && applicationContext.springSettings is PresentSpringSettings + && applicationContext.springTestType == SpringTestType.INTEGRATION_TEST ) { provider -> val relevantRepositories = concreteExecutor.getRelevantSpringRepositories(methodUnderTest.classId) logger.info { "Detected relevant repositories for class ${methodUnderTest.classId}: $relevantRepositories" } @@ -413,8 +427,7 @@ class UtBotSymbolicEngine( val springBeanValueProvider = SpringBeanValueProvider( defaultIdGenerator, beanNameProvider = { classId -> - (applicationContext as SpringApplicationContext).beanDefinitions - .filter { it.beanTypeName == classId.name } + (applicationContext as SpringApplicationContext).getBeansAssignableTo(classId) .map { it.beanName } }, relevantRepositories = relevantRepositories