From 5b8dd3558559414ce50436bdd64e04a318582560 Mon Sep 17 00:00:00 2001 From: Rustam Sadykov Date: Wed, 5 Oct 2022 13:21:28 +0300 Subject: [PATCH 1/2] fix assertions --- .../src/main/kotlin/org/utbot/framework/UtSettings.kt | 7 +++++++ .../codegen/model/constructor/tree/CgMethodConstructor.kt | 2 ++ 2 files changed, 9 insertions(+) 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 f21290f008..d0a5b45a22 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 @@ -240,6 +240,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/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 e664b005cd..d8c37c51bd 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 @@ -149,6 +149,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? @@ -365,6 +366,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 From bcc21257be54108c9a33c2ce3ae44c01de92befc Mon Sep 17 00:00:00 2001 From: Rustam Sadykov Date: Wed, 5 Oct 2022 14:42:38 +0300 Subject: [PATCH 2/2] fix test --- .../test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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(