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

Error in beforeTest listener is swallowed #1381

Closed
OliverCulleyDeLange opened this issue Apr 13, 2020 · 8 comments
Closed

Error in beforeTest listener is swallowed #1381

OliverCulleyDeLange opened this issue Apr 13, 2020 · 8 comments
Labels
bug 🐛 Issues that report a problem or error in the code. framework 🏗️ Pertains to the core structure and components of the Kotest framework.

Comments

@OliverCulleyDeLange
Copy link

OliverCulleyDeLange commented Apr 13, 2020

Kotest 4.0.2
I run a test which throws an exception in my beforeTest{} setup steps, however the process finishes with exit code 0, and no error is printed to console.

Example:

class TestingSpec : StringSpec() {
    init {
        beforeTest {
            throw ExceptionInInitializerError("Fail")
        }

        "test live data updated when doThing()" {
            true shouldBe false
        }
    }
}

Gives:

 "C:\Program Files\Android Studio\jre\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\Android Studio\lib\idea_rt.jar=55570:C:\Program Files\Android Studio\bin" -Dfile.encoding=UTF-8 -classpath "..." com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 uk.co.oliverdelange.wcr_android_kt.TestingSpec
~~~ Kotest Configuration ~~~
-> Parallelism: 1 thread(s)
-> Default test timeout: 600000ms
-> Default test order: TestCaseOrder
-> Default isolation mode: IsolationMode
-> Global soft assertations: False
-> Write spec failure file: False
-> Fail on ignored tests: False
-> Spec execution order: LexicographicSpecExecutionOrder
-> Extensions
  - io.kotest.core.extensions.SystemPropertyTagExtension
  - io.kotest.core.extensions.RuntimeTagExtension
  - io.kotest.core.extensions.IgnoredSpecDiscoveryExtension
  - io.kotest.core.extensions.TagFilteredDiscoveryExtension



Process finished with exit code 0```

Similar to https://github.com/kotest/kotest/issues/307 but thats closed. 
@sksamuel
Copy link
Member

There's plenty of tests around this, I will investigate.

@OliverCulleyDeLange
Copy link
Author

Interesting, the plot thickens. So i ran that test, in the kotest repo to see if its a platform issue (java version or windows related), and it passes ok.

I then tried to run my failing test through gradle test and it appeared to be fine, the test runs as expected and fails due to exception.

I then ran my failing test again through Android Studio and it worked :/ weird...

I did a gradle clean, and ran the test again through Android Studio and the process finished with exit code 0 with no errors on the console.

Then i tried gradle test again, but it didn't find any changes so didn't run anything. > Task :app:test UP-TO-DATE

Then after doing a clean and test again, my failing test isn't being found anymore, wheras my other tests are. Also, there appears to be a huge discrepancy with what is printed to the console when running via gradle cla, gradle via Android studio and via Android studio run configs.

Gradle version 6.3 here, i don't know enough about gradle to understand this. Which version of gradle do you use so i can try that?

@OliverCulleyDeLange
Copy link
Author

Aha, it has to do with the type of exception thrown from the beforeTest block.

RuntimeException works as expected.
ExceptionInInitializerError makes everything go a bit haywire... and this is the exception that was being thrown from my test.

Can you confirm this your side?

I beleive regardless of the type of exception thrown during the setup, the tests should always finish and spit out that exception on the console somehow.

@LeoColman LeoColman added bug 🐛 Issues that report a problem or error in the code. framework 🏗️ Pertains to the core structure and components of the Kotest framework. labels Apr 14, 2020
@sksamuel
Copy link
Member

sksamuel commented Apr 15, 2020 via email

@sksamuel
Copy link
Member

@ashishkujoy
Copy link
Contributor

@sksamuel ExceptionInInitializerError extends LinkageError which in jvm platform implementation of Try, we have marked it nonfatal error I think that's the reason it gets swallowed in beforeTest

inline operator fun <T> invoke(f: () -> T): Try<T> = try {
Success(f())
} catch (e: Throwable) {
if (nonFatal(e)) Failure(e) else throw e
}

actual fun nonFatal(t: Throwable): Boolean = when (t) {
is VirtualMachineError, is ThreadDeath, is InterruptedException, is LinkageError -> false
else -> true
}

https://docs.oracle.com/javase/8/docs/api/java/lang/ExceptionInInitializerError.html

@sksamuel
Copy link
Member

sksamuel commented Apr 24, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Issues that report a problem or error in the code. framework 🏗️ Pertains to the core structure and components of the Kotest framework.
Projects
None yet
Development

No branches or pull requests

4 participants