To runWriteActionAndWait or not and path confusion

I’m trying to rewrite a gutter test.

It copies files to the project. Running it it complains that I should use runWriteActionAndWait. I added it and it no longer complains.

// LightInsightTestCase = LightJavaCodeInsightFixtureTestCase5
class MappingAnnotationLineMarkerSpec: LightInsightTestCase() {

    override fun getTestDataPath(): String {
        return "src/test/testdata/interface-to-openapi/paths"
    }

    @Test
    fun `adds navigation gutter icon to mapping annotation`() {
        runWriteActionAndWait {
            fixture.copyDirectoryToProject("", "")
        }

        val gutters = fixture.findAllGutters("api/Api.java")
        assertEquals(2, gutters.size)
    }
}

What I do not understand is that existing tests (of IntelliJ) copy without runWriteActionAndWait. For example: DescriptionTypeRelatedItemLineMarkerProviderTest

Another issue I do not understand is that the file I check has a virtual file: temp:///src/api/Api.java but the project.basePath is somethink like /private/var/folders/8w/jcbd06095qxb0379t1rs9rfr0000gn/T/unitTest__35b5RtmSinu7SwZUBxg5EKvKSKt.

My gutter calculation walks the project/modules/source roots and it expects the src/api/Api.java below the project.basePath.

This works if I use the plugin but fails in the test.

Why don’t file and project base path match?

These tests are using different base classes and initialize the temp dir fixture differently.

If you check the sources, you’ll see that DescriptionTypeRelatedItemLineMarkerProviderTest creates a TempDirTestFixtureImpl under the hood. The frankenstein LightJavaCodeInsightFixtureTestCase5 creates a LightTempDirTestFixtureImpl.

The former creates temp files on disk, the latter (yours) creates temp files in memory.

The project directory is based on disk for both tests.

If I’m not mistaken, you could only add a execution policy to change the temp dir fixture implementation: intellij-community/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java at 222c7b2612a2241218ac7eaf0ec94048fc123d42 · JetBrains/intellij-community · GitHub

But I recommend to switch to the new way of JUnit5 tess, not the compatibility mode class which only provides limited functionality or configurability.

I can’t tell why you need a write action. The stacktrace is missing, most likely you’re not executing tests on the EDT or something else is different.

Thanks. That disk vs memory is a useful piece of information :slight_smile:

Using the “new” way was my plan. So let me try that again :slight_smile: