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

Weird behavior of should throw #164

Open
darmen opened this issue Oct 10, 2019 · 5 comments
Open

Weird behavior of should throw #164

darmen opened this issue Oct 10, 2019 · 5 comments

Comments

@darmen
Copy link

darmen commented Oct 10, 2019

Hi Markus!

I'm trying to do this:

    @Test
    fun `assert throws exceptions`() {
        invoking { factory.create("") } `should throw` IllegalArgumentException::class
    }

But have a compile error:

org/junit/ComparisonFailure
java.lang.NoClassDefFoundError: org/junit/ComparisonFailure
	at org.amshove.kluent.ExceptionsKt.shouldThrow(Exceptions.kt:14)
	at org.amshove.kluent.ExceptionsBacktickKt.should throw(ExceptionsBacktick.kt:5)
        ...

Do you have any clues?

@MarkusAmshove
Copy link
Owner

This looks like the the JUnit dependency for JVM isn't resolved.
Which Kluent and Kotlin versions are you using?
Any chance I can look into the project? e.g. is it open source or can you create a minimal repro?

@svenjacobs
Copy link

I'm having the same problem. The project uses Spek and not JUnit. I think Kluent should not have an implicit dependency on JUnit.

Maybe in shouldThrow() don't use ComparisonFailure explicitly but just check for the string name of the class?

@MarkusAmshove
Copy link
Owner

The dependency to JUnit is a known limitation at the moment, which I've got rid of (switched to kotlin.test) for the multiplatform branch.

The problem is, that using JUnit exceptions has better IDE integration (e.g. diff windows on comparison failures) which kotlin.test didn't do (at least at the time).

It might be worth to check out if this has been resolved in kotlin.test yet :-)

@fabianpiau
Copy link

I have the same error, my project is banning Junit 4 dependency, so can't use this type of assertion unfortunately. Can you make it work with Junit 5?

@MarkusAmshove
Copy link
Owner

The diff window for IntelliJ seems to also support formatting of the exception message, maybe we can build up on that.
The RegEx can be found here, although it has junit4 in the package name, so it needs to be tested if it works with something else than ComparisonFailure

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

4 participants