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