idea-plugin / arrow.meta.ide.testing.env / ideTest

ideTest

fun <A> ideTest(vararg tests: IdeTest<A>): Unit

This extension runs each test for selected editor features. Each Test class has to extend IdeTestSetUp, in order to spin-up the underlying IntelliJ Testing Platform at RunTime.

class ExampleTest: IdeTestSetUp() {
  /** test features **/
}

One IdeTest bundles the necessary components for a testSuit and the general schema looks like this:

@Test
fun `test feature`(): Unit =
 ideTest(
  IdeTest(
    myFixture, // the IntelliJ test environment spins up this value automatically
    code = "val exampleCode = 2",
    test = { code, myFixture ->
      /**
      * In addition to the parameters above the [IdeTestEnvironment] is in Scope, which bundles test operations
      * over the [IdeSyntax] and implements [IdeTestSyntax]. The latter composes a symmetric API over [IdeSyntax] in respect to tests.
      * That means an interface such as [LineMarkerSyntax] from the [IdeSyntax] is tested with [LineMarkerTestSyntax] from the [IdeTestSyntax].
      **/
       },
       result = // here we define what behavior is expected
      ),
      ... // you may add more test suit's for the same feature with different code examples and test's
    )

Given the helloWorld ide plugin, one concrete example may look like this:

@Test
fun `test if lineMarker is displayed`(): Unit =
  ideTest(
    IdeTest(
      myFixture = myFixture,
      code = """
      | fun helloWorld(): String =
      |   "Hello world!"
      """.trimIndent(),
      test = { code, myFixture ->
        collectLM(code, myFixture, ArrowIcons.ICON1) // this collect's all visible LineMarkers in the editor for a given Icon
      },
      result = resolves("LineMarker Test for helloWorld") {
        it.takeIf { collected ->
          collected.lineMarker.size == 1 // we expect that there is only one lineMarker in our example code
        }
      }
    )
  )

See Also

runTest

Do you like Arrow?

Arrow Org
<