diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt
index 165134a0c5..86f69e6d3a 100644
--- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt
+++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt
@@ -1599,7 +1599,23 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
} else {
setOf(annotation(testFramework.testAnnotationId))
}
- displayName?.let { testFrameworkManager.addDisplayName(it) }
+
+ /* Add a short test's description depending on the test framework type:
+ DisplayName annotation in case of JUni5, and description argument to Test annotation in case of TestNG.
+ */
+ if (displayName != null) {
+ when (testFramework) {
+ is Junit5 -> {
+ displayName.let { testFrameworkManager.addDisplayName(it) }
+ }
+ is TestNg -> {
+ testFrameworkManager.addTestDescription(displayName)
+ }
+ else -> {
+ // nothing
+ }
+ }
+ }
val result = currentExecution!!.result
if (result is UtTimeoutException) {
diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestFrameworkManager.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestFrameworkManager.kt
index df85554695..b33f2324c2 100644
--- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestFrameworkManager.kt
+++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/TestFrameworkManager.kt
@@ -15,7 +15,6 @@ import org.utbot.framework.codegen.model.constructor.context.CgContextOwner
import org.utbot.framework.codegen.model.constructor.util.CgComponents
import org.utbot.framework.codegen.model.constructor.util.classCgClassId
import org.utbot.framework.codegen.model.constructor.util.importIfNeeded
-import org.utbot.framework.codegen.model.tree.CgCommentedAnnotation
import org.utbot.framework.codegen.model.tree.CgEnumConstantAccess
import org.utbot.framework.codegen.model.tree.CgExpression
import org.utbot.framework.codegen.model.tree.CgGetJavaClass
@@ -174,13 +173,39 @@ internal abstract class TestFrameworkManager(val context: CgContext)
}
}
+ /**
+ * Supplements TestNG @Test annotation with a description.
+ * It looks like @Test(description="...")
+ *
+ * Should be used only with TestNG.
+ * @see issue-576 on GitHub
+ */
+ open fun addTestDescription(description: String?) {
+ if (description == null) return
+ val testAnnotation =
+ collectedMethodAnnotations.singleOrNull { it.classId == testFramework.testAnnotationId }
+
+ val descriptionArgument = CgNamedAnnotationArgument("description", stringLiteral(description))
+ if (testAnnotation is CgMultipleArgsAnnotation) {
+ testAnnotation.arguments += descriptionArgument
+ } else {
+ collectedMethodAnnotations += CgMultipleArgsAnnotation(
+ testFramework.testAnnotationId,
+ mutableListOf(descriptionArgument)
+ )
+ }
+ }
+
abstract fun disableTestMethod(reason: String)
- // We add a commented JUnit5 DisplayName annotation here by default,
- // because other test frameworks do not support such feature.
+ /**
+ * Adds @DisplayName annotation.
+ *
+ * Should be used only with JUnit 5.
+ * @see issue-576 on GitHub
+ */
open fun addDisplayName(name: String) {
- val displayName = CgSingleArgAnnotation(Junit5.displayNameClassId, stringLiteral(name))
- collectedMethodAnnotations += CgCommentedAnnotation(displayName)
+ collectedMethodAnnotations += CgSingleArgAnnotation(Junit5.displayNameClassId, stringLiteral(name))
}
protected fun ClassId.toExceptionClass(): CgExpression =