From ca598545266bab5895a4f2fcc8040066517aea8b Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Tue, 28 Jan 2025 22:12:41 +0100 Subject: [PATCH] Junit5 tests: replace cryptic error with more obvious one GitOrigin-RevId: 1573da1e431dec48b89a690bf1314f8e7e094cf7 --- .../junit5/src/fixture/TestFixtureImpl.kt | 11 ++++++++--- .../junit5/test/fixture/NoAnnotationTest.kt | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 platform/testFramework/junit5/test/fixture/NoAnnotationTest.kt diff --git a/platform/testFramework/junit5/src/fixture/TestFixtureImpl.kt b/platform/testFramework/junit5/src/fixture/TestFixtureImpl.kt index 558196358432..ca4ce7475549 100644 --- a/platform/testFramework/junit5/src/fixture/TestFixtureImpl.kt +++ b/platform/testFramework/junit5/src/fixture/TestFixtureImpl.kt @@ -1,8 +1,9 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.testFramework.junit5.fixture import com.intellij.platform.util.coroutines.attachAsChildTo import com.intellij.platform.util.coroutines.childScope +import com.intellij.testFramework.junit5.TestApplication import kotlinx.coroutines.* internal class TestFixtureImpl( @@ -19,8 +20,12 @@ internal class TestFixtureImpl( override fun get(): T { try { - @Suppress("UNCHECKED_CAST") - val deferred = _state as Deferred> + @Suppress("UNCHECKED_CAST", "TestOnlyProblems") + val deferred = _state as? Deferred> ?: error(""" + Fixture framework seems not be initialized. Make sure that: + 1. A test is written in Kotlin + 2. There is an annotation ${TestApplication::class.java.name} on top of your file. + """.trimIndent()) @OptIn(ExperimentalCoroutinesApi::class) return deferred.getCompleted().first } diff --git a/platform/testFramework/junit5/test/fixture/NoAnnotationTest.kt b/platform/testFramework/junit5/test/fixture/NoAnnotationTest.kt new file mode 100644 index 000000000000..ba90ed1cbd4a --- /dev/null +++ b/platform/testFramework/junit5/test/fixture/NoAnnotationTest.kt @@ -0,0 +1,14 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.testFramework.junit5.fixture + +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +class NoAnnotationTest { + @Test + fun testNoAnnotation() { + Assertions.assertThrows(IllegalStateException::class.java) { + projectFixture().get() + } + } +} \ No newline at end of file