From d2a2ce6145a8cc90d37039d54b9e11f98989d6d3 Mon Sep 17 00:00:00 2001 From: "eugene.nizienko" Date: Mon, 4 Mar 2024 12:38:10 +0100 Subject: [PATCH] jacoco UI tests coverage report --- .github/workflows/runUiTests.yml | 8 +++-- build.gradle.kts | 29 +++++++++++++++++++ src/test/kotlin/CreateSwitchPropertiesTest.kt | 25 +++++++++++----- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/.github/workflows/runUiTests.yml b/.github/workflows/runUiTests.yml index 380545c..01a5af9 100644 --- a/.github/workflows/runUiTests.yml +++ b/.github/workflows/runUiTests.yml @@ -57,9 +57,11 @@ jobs: - name: Move video if: ${{ failure() }} run: mv video build/reports - - - name: Save fails report - if: ${{ failure() }} + - name: Wait for reports + uses: jakejarvis/wait-action@master + with: + time: '10s' + - name: Save reports uses: actions/upload-artifact@v3 with: name: ${{ matrix.reportName }} diff --git a/build.gradle.kts b/build.gradle.kts index 8e047fc..840df71 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ plugins { id("java") id("org.jetbrains.kotlin.jvm") version "1.8.21" id("org.jetbrains.intellij") version "1.13.3" + jacoco } group = "com.github.nizienko" @@ -63,6 +64,21 @@ tasks.downloadRobotServerPlugin { version.set(robotVersion) } +jacoco { + toolVersion = "0.8.10" + applyTo(tasks.runIdeForUiTests.get()) +} + +val uiTestsCoverageReport = tasks.register("uiTestsCoverageReport") { + executionData(tasks.runIdeForUiTests.get()) + sourceSets(sourceSets.main.get()) + + reports { + xml.required.set(true) + html.required.set(true) + } +} + tasks.runIdeForUiTests { systemProperty("robot-server.port", "8082") systemProperty("ide.mac.message.dialogs.as.sheets", "false") @@ -73,6 +89,14 @@ tasks.runIdeForUiTests { systemProperty("apple.laf.useScreenMenuBar", "false") systemProperty("idea.trust.all.projects", "true") systemProperty("ide.show.tips.on.startup.default.value", "false") + + configure { + + // 221+ uses a custom classloader and jacoco fails to find classes + isIncludeNoLocationClasses = true + excludes = listOf("jdk.internal.*") + } + finalizedBy(uiTestsCoverageReport) } tasks.test { @@ -80,4 +104,9 @@ tasks.test { testLogging { events("passed", "skipped", "failed") } + + // we need the coverage from Idea process, not from test task + configure { + isEnabled = false + } } \ No newline at end of file diff --git a/src/test/kotlin/CreateSwitchPropertiesTest.kt b/src/test/kotlin/CreateSwitchPropertiesTest.kt index db77881..ddc7838 100644 --- a/src/test/kotlin/CreateSwitchPropertiesTest.kt +++ b/src/test/kotlin/CreateSwitchPropertiesTest.kt @@ -1,19 +1,30 @@ import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.fixtures.CommonContainerFixture -import com.intellij.remoterobot.fixtures.ComponentFixture -import com.intellij.remoterobot.fixtures.ContainerFixture -import com.intellij.remoterobot.fixtures.component +import com.intellij.remoterobot.fixtures.* import com.intellij.remoterobot.search.locators.byXpath import com.intellij.remoterobot.steps.CommonSteps import com.intellij.remoterobot.stepsProcessing.step import com.intellij.remoterobot.utils.keyboard import com.intellij.remoterobot.utils.waitFor +import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.Test import java.time.Duration class CreateSwitchPropertiesTest { - private val robot = RemoteRobot("http://127.0.0.1:8082") - private val steps = CommonSteps(robot) + companion object { + private val robot = RemoteRobot("http://127.0.0.1:8082") + private val steps = CommonSteps(robot) + + @JvmStatic + @AfterAll + fun afterAll(): Unit { + steps.invokeAction("Exit") + robot.idea { + find(byXpath("//div[@class='MyDialog']")) + .find(byXpath("//div[@text='Exit']")) + .click() + } + } + } @Test fun createPropSwitchFileTest() { @@ -21,7 +32,7 @@ class CreateSwitchPropertiesTest { robot.welcomeFrame { component(byXpath("//div[(@accessiblename='New Project' and @class='MainButton') or @defaulticon='createNewProjectTab.svg']")) .click() - component(byXpath("//div[@class='ProjectTypeListWithSearch']")) + component(byXpath("//div[@class='ProjectTypeListWithSearch']"), Duration.ofSeconds(15)) .findText("New Project") .click() component(byXpath("//div[contains(@action, 'Kotlin') and @class='SegmentedButton']"))