Skip to content

Skip test generation for abstract methods #550 #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class GenerateTestsCommand :
val classUnderTest: KClass<*> = loadClassBySpecifiedFqn(targetClassFqn)
val targetMethods = classUnderTest.targetMethods()
.filterWhen(UtSettings.skipTestGenerationForSyntheticMethods) { !isKnownSyntheticMethod(it) }
.filterNot { it.callable.isAbstract }
val testCaseGenerator = initializeGenerator(workingDirectory)

if (targetMethods.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.Computable
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiModifier
import com.intellij.psi.SyntheticElement
import com.intellij.refactoring.util.classMembers.MemberInfo
import com.intellij.testIntegration.TestIntegrationUtils
Expand Down Expand Up @@ -54,6 +55,7 @@ import org.utbot.common.filterWhen
import org.utbot.engine.util.mockListeners.ForceStaticMockListener
import org.utbot.framework.plugin.api.testFlow
import org.utbot.intellij.plugin.settings.Settings
import org.utbot.intellij.plugin.util.isAbstract
import kotlin.reflect.KClass
import kotlin.reflect.full.functions

Expand Down Expand Up @@ -152,6 +154,7 @@ object UtTestsDialogProcessor {
.filterWhen(UtSettings.skipTestGenerationForSyntheticMethods) {
it.member !is SyntheticElement
}
.filterNot { it.isAbstract }
DumbService.getInstance(project).runReadActionInSmartMode(Computable {
findMethodsInClassMatchingSelected(clazz, srcMethods)
})
Expand Down Expand Up @@ -189,9 +192,10 @@ object UtTestsDialogProcessor {
ForceStaticMockListener.create(testCaseGenerator, model.conflictTriggers)
}

val notEmptyCases = withUtContext(context) {
testCaseGenerator
.generate(
val notEmptyCases = runCatching {
withUtContext(context) {
testCaseGenerator
.generate(
methods,
model.mockStrategy,
model.chosenClassesToMockAlways,
Expand All @@ -203,9 +207,10 @@ object UtTestsDialogProcessor {
fuzzingValue = project.service<Settings>().fuzzingValue
}
)
.map { it.summarize(searchDirectory) }
.filterNot { it.executions.isEmpty() && it.errors.isEmpty() }
}
.map { it.summarize(searchDirectory) }
.filterNot { it.executions.isEmpty() && it.errors.isEmpty() }
}
}.getOrDefault(listOf())

if (notEmptyCases.isEmpty()) {
showErrorDialogLater(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.intellij.psi.PsiClass
import com.intellij.psi.PsiManager
import com.intellij.psi.PsiMethod
import com.intellij.psi.SyntheticElement
import com.intellij.psi.PsiModifier
import com.intellij.refactoring.PackageWrapper
import com.intellij.refactoring.ui.MemberSelectionTable
import com.intellij.refactoring.ui.PackageNameReferenceEditorCombo
Expand Down Expand Up @@ -129,6 +130,7 @@ import javax.swing.JComponent
import javax.swing.JList
import javax.swing.JPanel
import kotlin.streams.toList
import org.utbot.intellij.plugin.util.isAbstract

private const val RECENTS_KEY = "org.utbot.recents"

Expand Down Expand Up @@ -372,6 +374,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
if (srcClasses.size == 1) {
items = TestIntegrationUtils.extractClassMethods(srcClasses.single(), false)
.filterWhen(UtSettings.skipTestGenerationForSyntheticMethods) { it.member !is SyntheticElement }
.filterNot { it.isAbstract }
updateMethodsTable(items)
} else {
items = srcClasses.map { MemberInfo(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.utbot.intellij.plugin.util

import com.intellij.psi.PsiModifier
import com.intellij.psi.PsiModifierListOwner
import com.intellij.refactoring.classMembers.MemberInfoBase

val MemberInfoBase<out PsiModifierListOwner>.isAbstract: Boolean
get() = this.member.modifierList?.hasModifierProperty(PsiModifier.ABSTRACT)?: false
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ private fun prepareClass(kotlinClass: KClass<*>, methodNameFilter: String?): Lis
.filter { methodNameFilter?.equals(it.callable.name) ?: true }
.filterNot { it.isConstructor && (it.clazz.isAbstract || it.clazz.java.isEnum) }
.filterWhen(UtSettings.skipTestGenerationForSyntheticMethods) { !isKnownSyntheticMethod(it) }
.filterNot { it.callable.isAbstract }
.toList()

return if (kotlinClass.nestedClasses.isEmpty()) {
Expand Down