Skip to content
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

changed inheritance from AssertionError caused assertion not working with awaitility #213

Open
fvigotti opened this issue Sep 7, 2022 · 1 comment

Comments

@fvigotti
Copy link

fvigotti commented Sep 7, 2022

After a version update, I saw lot of test started to fail,
I've tracked down the issue to a compatibility issue between awaitility and kluent,

in awaitility ( maybe also in other libraries.. I don't know )
await untilAsserted { X shouldBeEqualTo Y }
the untilAsserted function expect the lambda assertion to return a AssertionError error , it seemed to be the case in the past ( with shouldBe , now deprecated in favor of shouldBeEqualTo ) but now it's changed and those assertion are just exceptions in kluent ,

a ugly workaround for me was overriding all those operators and wrap the exception in AssertionError
ie :

infix fun <I : Iterable<*>> I.assertShouldHaveSize(expectedSize: Int): I {
    return apply { try {
        this shouldHaveSize expectedSize
    }catch (cfe : ComparisonFailedException){
        throw AssertionError(cfe)
    }
}
}
@fvigotti fvigotti changed the title changed inheritance from AssertionError caused incompatibility with awaitility changed inheritance from AssertionError caused assertion not working with awaitility Sep 7, 2022
@drcolombo
Copy link
Contributor

I'm afraid, there's no clean way to achieve that, as awaitility catches only AssertionError to handle untilAsserted.
Kluent uses ComparisonFailedException in order to help IntelliJ/AS to show the comparison window. From other side (BTW, why did you decide that shouldBe is deprecated in flavor of shouldBeEqualTo? They are slightly different assertions), you can either use shouldBe (if it suites your needs) or wrap your lambda into assertSoftly (based on KotlinTest.kt):

@Test
fun untilAssertedTest() {
    Asynch(fakeRepository).perform()

    await untilAsserted {
        assertSoftly {
            fakeRepository.value shouldBeEqualTo 1
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants