diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt index 43fd1c1856..cf665be662 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt @@ -263,6 +263,13 @@ object UtSettings : AbstractSettings( */ var treatOverflowAsError: Boolean by getBooleanProperty(false) + /** + * Generate tests that treat assertions as error suits. + * + * True by default. + */ + var treatAssertAsErrorSuit: Boolean by getBooleanProperty(true) + /** * Instrument all classes before start */ diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt index 5560cd4e6a..9c18e0a1a1 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt @@ -5,7 +5,10 @@ import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.tests.infrastructure.isException import org.utbot.testcheckers.eq -class JavaAssertTest : UtValueTestCaseChecker(testClass = JavaAssert::class){ +class JavaAssertTest : UtValueTestCaseChecker( + testClass = JavaAssert::class, + testCodeGeneration = false +) { @Test fun testAssertPositive() { checkWithException( 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 824270f44e..773e180ce3 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 @@ -144,6 +144,7 @@ import org.utbot.summary.SummarySentenceConstants.TAB import java.lang.reflect.InvocationTargetException import java.security.AccessControlException import java.lang.reflect.ParameterizedType +import org.utbot.framework.UtSettings private const val DEEP_EQUALS_MAX_DEPTH = 5 // TODO move it to plugin settings? @@ -361,6 +362,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c if (exception is AccessControlException) return false // tests with timeout or crash should be processed differently if (exception is TimeoutException || exception is ConcreteExecutionFailureException) return false + if (UtSettings.treatAssertAsErrorSuit && exception is AssertionError) return false val exceptionRequiresAssert = exception !is RuntimeException || runtimeExceptionTestsBehaviour == PASS val exceptionIsExplicit = execution.result is UtExplicitlyThrownException