question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assertion failed are not shown without adding opentest4j dependency.

See original GitHub issue

Before adding opentest4j dependency, it shows this exception whenever assertion failed occur:

java.lang.NoClassDefFoundError: org/opentest4j/AssertionFailedError
	at strikt.internal.AssertionStrategy.createAssertionFailedError$strikt_core(AssertionStrategy.kt:195)
	at strikt.internal.AssertionStrategy$Throwing.afterStatusSet(AssertionStrategy.kt:151)
	at strikt.internal.AssertionStrategy$appendAtomic$1.fail(AssertionStrategy.kt:44)
	at strikt.api.AtomicAssertion$DefaultImpls.fail$default(AtomicAssertion.kt:19)
	at strikt.assertions.CollectionKt$hasSize$1.invoke(Collection.kt:12)
	at strikt.assertions.CollectionKt$hasSize$1.invoke(Collection.kt)
	at strikt.internal.AssertionBuilder.assert(AssertionBuilder.kt:64)
	at strikt.internal.AssertionBuilder.assert(AssertionBuilder.kt:11)
	at strikt.assertions.CollectionKt.hasSize(Collection.kt:9)
       at ....
	at org.spekframework.spek2.runtime.scope.TestScopeImpl.execute(Scopes.kt:94)
	at org.spekframework.spek2.runtime.Executor$execute$$inlined$executeSafely$lambda$1$1.invokeSuspend(Executor.kt:52)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:740)
Caused by: java.lang.ClassNotFoundException: org.opentest4j.AssertionFailedError
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 18 more

After I added testImplementation group: 'org.opentest4j', name: 'opentest4j', version: '1.2.0', everything works fine.

I’m using spek version 2.0.6 for testing an Android app. It works fine with other assertion library like AssertJ.

P/S I think it is still not fine after I adding opentest4j dependency. Here is what I got after addin the dependency:

  ✗ has size 2 : found 1
org.opentest4j.AssertionFailedError: ▼ Expect that [Mock for Class, hashCode: 17337594]:
  ✗ has size 2 : found 1
	at ...
	at ....
	at org.spekframework.spek2.runtime.scope.TestScopeImpl.execute(Scopes.kt:94)
	at org.spekframework.spek2.runtime.Executor$execute$$inlined$executeSafely$lambda$1$1.invokeSuspend(Executor.kt:52)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
	Suppressed: org.opentest4j.AssertionFailedError
		at strikt.internal.AssertionStrategy.createAssertionFailedError$strikt_core(AssertionStrategy.kt:195)
		at strikt.internal.AssertionStrategy$Throwing.afterStatusSet(AssertionStrategy.kt:151)
		at strikt.internal.AssertionStrategy$appendAtomic$1.fail(AssertionStrategy.kt:44)
		at strikt.api.AtomicAssertion$DefaultImpls.fail$default(AtomicAssertion.kt:19)
		at strikt.assertions.CollectionKt$hasSize$1.invoke(Collection.kt:12)
		at strikt.assertions.CollectionKt$hasSize$1.invoke(Collection.kt)
		at strikt.internal.AssertionBuilder.assert(AssertionBuilder.kt:64)
		at strikt.internal.AssertionBuilder.assert(AssertionBuilder.kt:11)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
robfletchercommented, Sep 25, 2019

That’s a deliberate bit of behavior so that the stack trace originates at the line in your test where the assertion is. Any internal stack frames from the strikt code are shifted into the suppressed section.

0reactions
robfletchercommented, Sep 25, 2019

No problem. Thanks for the bug report!

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NoClassDefFoundError: org/opentest4j ...
I have an assertion library that uses opentest4j for assertion failures. There should be no requirement to run these tests under junit5.
Read more >
Mockito / Junit5 org.opentest4j.AssertionFailedError for getter()
A test has to be straight understandable and that is not. It took me about 5 mn to understand the error cause. It...
Read more >
Gradle test shows AssertionError, but not exception message
I am possibly doing something wrong here, but I cannot get gradle to print the actual failed assertion message given the following test:...
Read more >
JUnit 5 Tutorial: Writing Assertions With AssertJ
Know how we can write basic assertions with AssertJ. Understand how we can customize the error message shown when an assertion fails.
Read more >
Testing that no exception was thrown in Java - Dev Genius
TestNG takes a different tack to unexpected exceptions. If an unexpected exception occurs, the test fails just the same as if an assertion...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found