fbpx

Test execution basics: passed, failed, crashed

In Junit based testing framework there are few possible test outcomes: passed, failed and crashed. In this short note we will dive into that mechanisms.

Test will pass, if no exception is thrown. Empty test should always pass:

class TestFlowShowcase : StringSpec({
    "it should pass"{
        // nothing here
    }
})

Or test with assertion that passes:

class TestFlowShowcase : StringSpec({
    "1 == 1"{
        (1 == 1) shouldBe true
    }
})

Test will fail, if AssertionException (or descendant) would be thrown:

class TestFlowShowcase : StringSpec({
   "it should fail"{
        throw AssertionError("fail")
    }
})

Test will crash, if other exception would be thrown:

class TestFlowShowcase : StringSpec({
    "it should crash"{
        throw Exception("it crashed")
    }
})

How to treat different test outcomes?

PassedNo error was thrown
FailedAssertionError was thrown in test
CrashedOther exception was thrown

“Green” test means only that no error was thrown during test execution – it may also mean that no assertion was performed.

Usually test failed means that something is wrong with system under test – it doesn’t meet expectations defined in assertions.

Test crash indicate that something is wrong with test itself – it does not handle exception thrown in system under test, or its mocks are misconfigured.


more insights

Uncategorized
Jarosław Michalik

#kotlinDevChallenge 2023 summary

The KotlinDevChallenge was not just a competition, but a journey of learning, growth, and community engagement. Every participant in this challenge is a winner in

Read More »
KotlinDevChallenge2023
Jarosław Michalik

#kotlinDevChallenge – 24

What do you love most about Kotlin? Productivity increase? Idioms? Or that it isn’t Java? Maybe something else! Share it. It can be short. It

Read More »

AndroidPro newsletter 🚀

join 3057 developers reading AndroidPro newsletter every week

👉 tips & tricks, articles, videos

👉 every Thursday in your inbox

🎁 bonus on signup – Clean Architecture blueprint

brought to you by Jarek Michalik, Kotlin GDE

You can unsubscribe any time. For details visit our privacy policy.

android pro newsletter tips and tricks how to learn android