diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt
index a8ce52c0a1..4a5f41709a 100644
--- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt
+++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt
@@ -569,7 +569,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
         try {
             val contentEntry = modifiableModel.contentEntries
                 .filterNot { it.file == null }
-                .firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, true) }
+                .firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, false) }
                 ?: return false
 
             contentEntry.addSourceRootIfAbsent(
diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/components/TestFolderComboWithBrowseButton.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/components/TestFolderComboWithBrowseButton.kt
index 01eadc7868..cd9389b573 100644
--- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/components/TestFolderComboWithBrowseButton.kt
+++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/components/TestFolderComboWithBrowseButton.kt
@@ -16,6 +16,7 @@ import javax.swing.JList
 import org.utbot.common.PathUtil
 import org.utbot.intellij.plugin.models.GenerateTestsModel
 import org.utbot.intellij.plugin.ui.utils.addDedicatedTestRoot
+import org.utbot.intellij.plugin.ui.utils.isGradle
 import org.utbot.intellij.plugin.ui.utils.suitableTestSourceRoots
 
 class TestFolderComboWithBrowseButton(private val model: GenerateTestsModel) : ComboboxWithBrowseButton() {
@@ -23,6 +24,10 @@ class TestFolderComboWithBrowseButton(private val model: GenerateTestsModel) : C
     private val SET_TEST_FOLDER = "set test folder"
 
     init {
+        if (model.project.isGradle()) {
+            setButtonEnabled(false)
+            button.toolTipText = "Please define custom test source root via Gradle"
+        }
         childComponent.isEditable = false
         childComponent.renderer = object : ColoredListCellRenderer<Any?>() {
             override fun customizeCellRenderer(
diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/ModuleUtils.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/ModuleUtils.kt
index 2d4fbbf79f..59e03e3a3d 100644
--- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/ModuleUtils.kt
+++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/ModuleUtils.kt
@@ -1,5 +1,6 @@
 package org.utbot.intellij.plugin.ui.utils
 
+import com.android.tools.idea.gradle.project.GradleProjectInfo
 import org.utbot.common.PathUtil.toPath
 import org.utbot.common.WorkaroundReason
 import org.utbot.common.workaround
@@ -144,14 +145,14 @@ private fun Module.suitableTestSourceFolders(codegenLanguage: CodegenLanguage):
         // Heuristics: User is more likely to choose the shorter path
         .sortedBy { it.url.length }
 }
+fun Project.isGradle() = GradleProjectInfo.getInstance(this).isBuildWithGradle
 
 private const val dedicatedTestSourceRootName = "utbot_tests"
 fun Module.addDedicatedTestRoot(testSourceRoots: MutableList<VirtualFile>): VirtualFile? {
+    // Don't suggest new test source roots for Gradle project where 'unexpected' test roots won't work
+    if (project.isGradle()) return null
     // Dedicated test root already exists
-    // OR it looks like standard structure of Gradle project where 'unexpected' test roots won't work
-    if (testSourceRoots.any { file ->
-            file.name == dedicatedTestSourceRootName || file.path.endsWith("src/test/java")
-        }) return null
+    if (testSourceRoots.any { file -> file.name == dedicatedTestSourceRootName }) return null
 
     val moduleInstance = ModuleRootManager.getInstance(this)
     val testFolder = moduleInstance.contentEntries.flatMap { it.sourceFolders.toList() }