From b1307e6ef8beee37186dd62decef7a26d00ce082 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Tue, 12 Sep 2023 11:07:07 +0300 Subject: [PATCH 01/16] Spring autotests: Unit test generation and UI action dialog checks. Soft assertion in UTBot regular Java test. Some fixes to regular Java tests. --- .../src/test/kotlin/org/utbot/data/RunInfo.kt | 9 +- .../utbot/dialogs/UnitTestBotDialogFixture.kt | 85 ++++++++- .../test/kotlin/org/utbot/pages/IdeaFrame.kt | 11 +- .../kotlin/org/utbot/pages/IdeaGradleFrame.kt | 22 +-- .../kotlin/org/utbot/pages/WelcomeFrame.kt | 3 +- .../kotlin/org/utbot/samples/CodeSamples.kt | 4 +- .../test/kotlin/org/utbot/steps/IDESteps.kt | 8 + .../test/kotlin/org/utbot/tests/BaseTest.kt | 44 ++++- .../org/utbot/tests/SpringUTBotActionTest.kt | 173 ++++++++++++++++++ ...estBotActionTest.kt => UTBotActionTest.kt} | 26 ++- 10 files changed, 341 insertions(+), 44 deletions(-) create mode 100644 utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt rename utbot-intellij/src/test/kotlin/org/utbot/tests/{UnitTestBotActionTest.kt => UTBotActionTest.kt} (76%) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt index f91630c119..fe379aa9ac 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt @@ -4,8 +4,9 @@ import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.Random -val TEST_RUN_NUMBER = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss")) -val DEFAULT_TEST_GENERATION_TIMEOUT = 60L +val TEST_RUN_NUMBER: String = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))!! +const val DEFAULT_TEST_GENERATION_TIMEOUT = 60L val NEW_PROJECT_NAME_START = "Aut_${TEST_RUN_NUMBER}_" -val DEFAULT_PROJECT_DIRECTORY = "~\\IdeaProjects" -var random: Random = Random() +const val DEFAULT_PROJECT_DIRECTORY = "~\\IdeaProjects" +const val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" +val random: Random = Random() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt index 0a411ea440..9d6975f02d 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt @@ -5,6 +5,7 @@ import com.intellij.remoterobot.data.RemoteComponent import com.intellij.remoterobot.fixtures.* import com.intellij.remoterobot.search.locators.byXpath import com.intellij.remoterobot.utils.Keyboard +import java.time.Duration @FixtureName("UnitTestBotDialog") @DefaultXpath("Dialog type", "//*[contains(@title, 'UnitTestBot')]") @@ -21,12 +22,94 @@ class UnitTestBotDialogFixture( get() = actionLink( byXpath("//div[@class='SdkNotificationPanel']//div[@class='HyperlinkLabel']")) + val testSourcesRootLabel + get() = jLabel( + byXpath("//div[@text='Test sources root:']")) + val testSourcesRootComboBox get() = comboBox( - byXpath("//div[@class='TestFolderComboWithBrowseButton']/div[1]")) + byXpath("//div[@class='TestFolderComboWithBrowseButton']/div[@class='ComboBox']")) + + val testingFrameworkLabel + get() = jLabel( + byXpath("//div[@text='Testing framework:']")) + + val testingFrameworkComboBox + get() = comboBox( + byXpath("//div[@accessiblename='Testing framework:' and @class='ComboBox']")) + + val mockingStrategyLabel + get() = jLabel( + byXpath("//div[@text='Mocking strategy:']")) + + val mockingStrategyComboBox + get() = comboBox( + byXpath("//div[@accessiblename='Mocking strategy:' and @class='ComboBox']")) + + val mockStaticMethodsCheckbox + get() = checkBox( + byXpath("//div[@text='Mock static methods']")) + + val parameterizedTestsCheckbox + get() = checkBox( + byXpath("//div[@text='Parameterized tests']")) + + val testGenerationTimeoutLabel + get() = jLabel( + byXpath("//div[@text='Test generation timeout:']")) + + val testGenerationTimeoutTextField + get() = textField( + byXpath("//div[@class='JFormattedTextField']")) + + val timeoutSecondsPerClassLabel + get() = jLabel( + byXpath("//div[@text='seconds per class']")) + + val generateTestsForLabel + get() = jLabel( + byXpath("//div[@text='Generate tests for:']")) + + val memberListTable + get() = remoteRobot.find(byXpath("//div[@class='MemberSelectionTable']"), + Duration.ofSeconds(5) + ) val generateTestsButton get() = button( byXpath("//div[@class='MainButton']")) + val arrowOnGenerateTestsButton + get() = button( + byXpath("//div[@class='JBOptionButton' and @text='Generate Tests']//div[@class='ArrowButton']")) + + val buttonsList + get() = heavyWeightWindow().itemsList + + + // Spring-specific elements + val springConfigurationLabel + get() = jLabel( + byXpath("//div[@text='Spring configuration:']")) + + val springConfigurationComboBox + get() = comboBox( + byXpath("//div[@accessiblename='Spring configuration:' and @class='ComboBox']")) + + val springTestsTypeLabel + get() = jLabel( + byXpath("//div[@text='Tests type:']")) + + val springTestsTypeComboBox + get() = comboBox( + byXpath("//div[@accessiblename='Tests type:' and @class='ComboBox']")) + + val springActiveProfilesLabel + get() = jLabel( + byXpath("//div[@text='Active profile(s):']")) + + val springActiveProfilesTextField + get() = textField( + byXpath("//div[@accessiblename='Active profile(s):' and @class='JBTextField']")) + } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt index 317cd626a6..e0efef997b 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt @@ -109,10 +109,13 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) } catch (ignore: Throwable) {} } - fun openUTBotDialogFromProjectViewForClass(classname: String) { + fun openUTBotDialogFromProjectViewForClass(classname: String, packageName: String = "") { step("Call UnitTestBot action") { waitFor(ofSeconds(200)) { !isDumbMode() } with(projectViewTree) { + if (hasText(classname).not() && packageName != "") { + findText{it.text.endsWith(packageName)}.doubleClick() + } findText(classname).click(MouseButton.RIGHT_BUTTON) } remoteRobot.actionMenuItem("Generate Tests with UnitTestBot...").click() @@ -120,6 +123,8 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) } open fun waitProjectIsOpened() { + projectViewTree.click() + keyboard { key(KeyEvent.VK_PAGE_UP) } waitForIgnoringError(ofSeconds(30)) { projectViewTree.hasText(projectName) } @@ -129,7 +134,7 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) waitProjectIsOpened() } - open fun expandProjectTree(projectName: String) { + open fun expandProjectTree() { with(projectViewTree) { if (hasText("src").not()) { findText(projectName).doubleClick() @@ -158,8 +163,6 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) fun createNewJavaClass(newClassname: String = "Example", textToClickOn: String = "Main") { - waitProjectIsOpened() - expandProjectTree(projectName) with(projectViewTree) { findText(textToClickOn).click(MouseButton.RIGHT_BUTTON) } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt index 52d0fad081..8f2ec29a69 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt @@ -19,30 +19,30 @@ class IdeaGradleFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent } } - override fun expandProjectTree(projectName: String) { + override fun expandProjectTree() { with(projectViewTree) { waitForIgnoringError(ofSeconds(10)) { hasText("src") } if (hasText("src").not()) { findText(projectName).doubleClick() - waitForIgnoringError{ - hasText("src") - } + } + waitForIgnoringError{ + hasText("main") } if (hasText("main").not()) { findText("src").doubleClick() - waitForIgnoringError{ - hasText("src").and(hasText("main")) - } + } + waitForIgnoringError{ + hasText("src").and(hasText("main")) } if (hasText("java").not()) { findText("main").doubleClick() - waitForIgnoringError{ - hasText("src").and(hasText("main")).and(hasText("java")) - } } - if (hasText("Main").not()) { + waitForIgnoringError{ + hasText("src").and(hasText("main")).and(hasText("java")) + } + if (hasText {it.text.startsWith("org") || it.text.startsWith("com")}.not()) { findText("java").doubleClick() } } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt index 16eab0011f..1e46cd7611 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt @@ -38,8 +38,7 @@ class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : val newProjectDialog get() = remoteRobot.find(NewProjectDialogFixture::class.java) - fun openProjectByPath(projectName: String, - location: String = "") { + fun openProjectByPath(location: String, projectName: String = "") { val localPath = location + projectName openProjectLink.click() keyboard.enterText(localPath) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/samples/CodeSamples.kt b/utbot-intellij/src/test/kotlin/org/utbot/samples/CodeSamples.kt index 0464782fe3..5fe1cc06a1 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/samples/CodeSamples.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/samples/CodeSamples.kt @@ -13,7 +13,7 @@ fun TextEditorFixture.typeAdditionFunction(className: String): String { enterText("public int addition(") enterText("int a, int b") key(KeyEvent.VK_END) - enterText("{") + enterText(" {") enter() enterText("// Test run ${TEST_RUN_NUMBER}") enter() @@ -30,7 +30,7 @@ fun TextEditorFixture.typeDivisionFunction(className: String) : String { enterText("public int division(") enterText("int a, int b") key(KeyEvent.VK_END) - enterText("{") + enterText(" {") enter() enterText("// Test run ${TEST_RUN_NUMBER}") enter() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/steps/IDESteps.kt b/utbot-intellij/src/test/kotlin/org/utbot/steps/IDESteps.kt index c6dc22c7b3..7119df5ebf 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/steps/IDESteps.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/steps/IDESteps.kt @@ -1,5 +1,6 @@ package org.utbot.steps +import com.intellij.remoterobot.fixtures.JButtonFixture import com.intellij.remoterobot.fixtures.TextEditorFixture import com.intellij.remoterobot.fixtures.dataExtractor.contains import com.intellij.remoterobot.search.locators.byXpath @@ -38,6 +39,13 @@ fun TextEditorFixture.goToLineAndColumn(row: Int, column: Int) { } } +fun TextEditorFixture.closeAllTabs() { + val closeTabButtons = remoteRobot.findAll(byXpath("//div[@class='EditorTabs']//div[@myicon='close.svg']")) + closeTabButtons.forEach { + it.click() + } +} + fun IdeaFrame.closeTipOfTheDay() { step("Close Tip of the Day if it appears") { waitFor(ofSeconds(20)) { diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt index 2978faa03d..b64969ce77 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt @@ -1,6 +1,7 @@ package org.utbot.tests import com.intellij.remoterobot.RemoteRobot +import com.intellij.remoterobot.utils.waitFor import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach @@ -8,10 +9,8 @@ import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.params.provider.Arguments import org.utbot.data.IdeaBuildSystem import org.utbot.data.JDKVersion -import org.utbot.pages.IdeaFrame -import org.utbot.pages.IdeaGradleFrame -import org.utbot.pages.IdeaMavenFrame -import org.utbot.pages.idea +import org.utbot.data.NEW_PROJECT_NAME_START +import org.utbot.pages.* import org.utbot.utils.RemoteRobotExtension import org.utbot.utils.StepsLogger import java.time.Duration.ofSeconds @@ -19,10 +18,10 @@ import java.time.Duration.ofSeconds @ExtendWith(RemoteRobotExtension::class) open class BaseTest { fun getIdeaFrameForBuildSystem(remoteRobot: RemoteRobot, ideaBuildSystem: IdeaBuildSystem): IdeaFrame { - when (ideaBuildSystem) { - IdeaBuildSystem.INTELLIJ -> return remoteRobot.find(IdeaFrame::class.java, ofSeconds(10)) - IdeaBuildSystem.GRADLE -> return remoteRobot.find(IdeaGradleFrame::class.java, ofSeconds(10)) - IdeaBuildSystem.MAVEN -> return remoteRobot.find(IdeaMavenFrame::class.java, ofSeconds(10)) + return when (ideaBuildSystem) { + IdeaBuildSystem.INTELLIJ -> remoteRobot.find(IdeaFrame::class.java, ofSeconds(10)) + IdeaBuildSystem.GRADLE -> remoteRobot.find(IdeaGradleFrame::class.java, ofSeconds(10)) + IdeaBuildSystem.MAVEN -> remoteRobot.find(IdeaMavenFrame::class.java, ofSeconds(10)) } } @@ -42,14 +41,39 @@ open class BaseTest { } } + fun createProjectWithJDK( + projectName:String = "", + ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, + remoteRobot: RemoteRobot + ) { + var newProjectName = projectName + if (projectName == "") { + newProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number + } + remoteRobot.welcomeFrame { + createNewProject( + newProjectName, + buildSystem = ideaBuildSystem, + jdkVersion = jdkVersion + ) + } + val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) + with(ideaFrame) { + waitProjectIsCreated() + waitFor(ofSeconds(30)) { + !isDumbMode() + } + } + } + companion object { @BeforeAll @JvmStatic - fun init(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { + fun init(remoteRobot: RemoteRobot) { StepsLogger.init() } - private val supportedProjectsList: List = + internal val supportedProjectsList: List = addPairsToList(true) private val unsupportedProjectsList: List = addPairsToList(false) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt new file mode 100644 index 0000000000..27b7b48f9f --- /dev/null +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -0,0 +1,173 @@ +package org.utbot.tests + +import com.intellij.remoterobot.RemoteRobot +import com.intellij.remoterobot.utils.waitForIgnoringError +import org.assertj.core.api.SoftAssertions +import org.junit.jupiter.api.* +import org.utbot.data.IdeaBuildSystem +import org.utbot.pages.welcomeFrame +import java.time.Duration + +class SpringUTBotActionTest : BaseTest() { + val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" + val SPRING_PROJECT_DIRECTORY = "D:\\\\JavaProjects\\\\spring\\\\" + val APP_PACKAGE_NAME = "org.springframework.samples.petclinic" + val EXISTING_PACKAGE_NAME = "vet" + val EXISTING_CLASS_NAME = "VetController" + + @BeforeEach + fun openExistingSpringProject (remoteRobot: RemoteRobot) { + remoteRobot.welcomeFrame { + try { + findText(SPRING_EXISTING_PROJECT_NAME).click() + } catch (ignore: NoSuchElementException) { + openProjectByPath(SPRING_PROJECT_DIRECTORY, SPRING_EXISTING_PROJECT_NAME) + } + } + val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) + return with (ideaFrame) { + waitProjectIsOpened() + expandProjectTree() + } + } + + @Test + @DisplayName("Check action dialog UI default state in a Spring project") + @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) + fun checkSpringDefaultActionDialog(remoteRobot: RemoteRobot) { + val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) + return with (ideaFrame) { + openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) + with (unitTestBotDialog) { + val softly = SoftAssertions() + softly.assertThat(springConfigurationLabel.isVisible()) + softly.assertThat(springConfigurationComboBox.isShowing) + softly.assertThat(springConfigurationComboBox.selectedText()== "No Configuration") + softly.assertThat(springConfigurationComboBox.listValues() + .containsAll(listOf("No Configuration", "PetClinicApplication", "CacheConfiguration"))) + softly.assertThat(springTestsTypeLabel.isVisible()) + softly.assertThat(springTestsTypeComboBox.isShowing) + softly.assertThat(springTestsTypeComboBox.selectedText() == "Unit tests") + softly.assertThat(springActiveProfilesLabel.isShowing) + softly.assertThat(springActiveProfilesTextField.text =="default") + softly.assertThat(mockingStrategyLabel.isVisible()) + softly.assertThat(mockingStrategyComboBox.selectedText() == "Mock everything outside the class") + softly.assertThat(mockingStrategyComboBox.listValues() + .containsAll(listOf("Do not mock", "Mock everything outside the package", "Mock everything outside the class"))) + softly.assertThat(mockStaticMethodsCheckbox.isShowing) + softly.assertThat(parameterizedTestsCheckbox.isShowing) + softly.assertThat(parameterizedTestsCheckbox.isSelected().not()) + softly.assertThat(testGenerationTimeoutLabel.isShowing) + softly.assertThat(testGenerationTimeoutTextField.text.isNotEmpty()) + softly.assertThat(memberListTable.isShowing) + softly.assertThat(memberListTable.columnCount == 1) + softly.assertThat(memberListTable.rowCount == 2) + softly.assertThat(memberListTable.data.getAll().map { it.text } + .containsAll(listOf("showResourcesVetList():Vets", "showVetList(page:int, model:Model):String"))) + softly.assertThat(generateTestsButton.isEnabled()) + softly.assertThat(arrowOnGenerateTestsButton.isShowing) + arrowOnGenerateTestsButton.click() + softly.assertThat(buttonsList.isShowing) + softly.assertThat(buttonsList.collectItems().containsAll(listOf("Generate Tests", "Generate and Run"))) + softly.assertAll() + } + } + } + + @Test + @DisplayName("Check action dialog UI when Spring configuration is selected") + @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) + fun checkActionDialogWithSpringConfiguration(remoteRobot: RemoteRobot) { + val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) + return with (ideaFrame) { + openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) + with (unitTestBotDialog) { + springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ + heavyWeightWindow().itemsList.clickItem("PetClinicApplication") + val softly = SoftAssertions() + softly.assertThat(springConfigurationComboBox.selectedText()== "PetClinicApplication") + softly.assertThat(springConfigurationComboBox.listValues() + .containsAll(listOf("No Configuration", "PetClinicApplication", "CacheConfiguration"))) + softly.assertThat(springTestsTypeComboBox.selectedText() == "Unit tests") + softly.assertThat(springActiveProfilesTextField.text =="default") + softly.assertThat(generateTestsButton.isEnabled()) + softly.assertAll() + } + } + } + + @Test + @DisplayName("Check action dialog UI when Integration tests are selected") + @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) + fun checkActionDialogWithIntegrationTests(remoteRobot: RemoteRobot) { + val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) + return with (ideaFrame) { + openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) + with (unitTestBotDialog) { + springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ + heavyWeightWindow().itemsList.clickItem("PetClinicApplication") + springTestsTypeComboBox.selectItem("Integration tests") + val softly = SoftAssertions() + softly.assertThat(springConfigurationComboBox.selectedText()== "PetClinicApplication") + softly.assertThat(springConfigurationComboBox.listValues() + .containsAll(listOf("No Configuration", "PetClinicApplication", "CacheConfiguration"))) + softly.assertThat(springTestsTypeComboBox.selectedText() == "Unit tests") + softly.assertThat(springActiveProfilesTextField.text =="default") + softly.assertThat(generateTestsButton.isEnabled()) + softly.assertAll() + } + } + } + + @Test + @DisplayName("Check Spring Unit tests generation") + @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("Unit tests"), Tag("Generate tests")) + fun checkSpringUnitTestsGeneration(remoteRobot: RemoteRobot) { + val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) + return with (ideaFrame) { + openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) + with (unitTestBotDialog) { + springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ + heavyWeightWindow().itemsList.clickItem("PetClinicApplication") + unitTestBotDialog.generateTestsButton.click() + waitForIgnoringError (Duration.ofSeconds(5)){ + inlineProgressTextPanel.isShowing + } + waitForIgnoringError (Duration.ofSeconds(60)){ + inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") + } + waitForIgnoringError(Duration.ofSeconds(60)) { + utbotNotification.title.hasText("UnitTestBot: unit tests generated successfully") + } + val softly = SoftAssertions() + softly.assertThat(utbotNotification.body.hasText("Target: org.springframework.samples.petclinic.vet.VetController Overall test methods: 7")) + softly.assertThat(textEditor().editor.text).contains("class ${EXISTING_CLASS_NAME}Test") + softly.assertThat(textEditor().editor.text).contains("@Test\n") + softly.assertThat(textEditor().editor.text).contains(CONTEXT_LOADS_TEST_TEXT) + softly.assertThat(textEditor().editor.text).contains("@utbot.classUnderTest {@link ${EXISTING_CLASS_NAME}}") + softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${EXISTING_CLASS_NAME}#showResourcesVetList") + softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${EXISTING_CLASS_NAME}#showVetList") + softly.assertAll() + } + } + } + + + @AfterEach + fun closeDialogIfNotClosed (remoteRobot: RemoteRobot) { + val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) + with (ideaFrame) { + try { + unitTestBotDialog.closeButton.click() + } catch (ignore: Throwable) {} + } + } + + val CONTEXT_LOADS_TEST_TEXT = """ /** + * This sanity check test fails if the application context cannot start. + */ + @Test + public void contextLoads() { + }""" + +} \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/UnitTestBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt similarity index 76% rename from utbot-intellij/src/test/kotlin/org/utbot/tests/UnitTestBotActionTest.kt rename to utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt index 3d5f7acb87..94226170a1 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/UnitTestBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt @@ -3,6 +3,7 @@ package org.utbot.tests import com.intellij.remoterobot.RemoteRobot import com.intellij.remoterobot.utils.waitForIgnoringError import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.SoftAssertions import org.junit.jupiter.api.* import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource @@ -14,11 +15,10 @@ import org.utbot.samples.typeAdditionFunction import org.utbot.samples.typeDivisionFunction import java.time.Duration.ofSeconds -class UnitTestBotActionTest : BaseTest() { - +class UTBotActionTest : BaseTest() { @ParameterizedTest(name = "Generate tests in {0} project with JDK {1}") @MethodSource("supportedProjectsProvider") - @Tags(Tag("Java"), Tag("UnitTestBot"), Tag("Positive")) + @Tags(Tag("Java"), Tag("UnitTestBot"), Tag("Positive"), Tag("Generate tests")) fun checkBasicTestGeneration(ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, remoteRobot: RemoteRobot) { val createdProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number @@ -27,6 +27,8 @@ class UnitTestBotActionTest : BaseTest() { } val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) with (ideaFrame) { + waitProjectIsOpened() + expandProjectTree() val newClassName = "Arithmetic" createNewJavaClass(newClassName, "Main") val returnsFromTagBody = textEditor().typeDivisionFunction(newClassName) @@ -41,20 +43,22 @@ class UnitTestBotActionTest : BaseTest() { waitForIgnoringError(ofSeconds(30)) { utbotNotification.title.hasText("UnitTestBot: unit tests generated successfully") } - assertThat(textEditor().editor.text).contains("class ${newClassName}Test") - assertThat(textEditor().editor.text).contains("@Test\n") - assertThat(textEditor().editor.text).contains("assertEquals(") - assertThat(textEditor().editor.text).contains("@utbot.classUnderTest {@link ${newClassName}}") - assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${newClassName}#") - assertThat(textEditor().editor.text).contains(returnsFromTagBody) + val softly = SoftAssertions() + softly.assertThat(textEditor().editor.text).contains("class ${newClassName}Test") + softly.assertThat(textEditor().editor.text).contains("@Test\n") + softly.assertThat(textEditor().editor.text).contains("assertEquals(") + softly.assertThat(textEditor().editor.text).contains("@utbot.classUnderTest {@link ${newClassName}}") + softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${newClassName}#") + softly.assertThat(textEditor().editor.text).contains(returnsFromTagBody) //ToDo verify how many tests are generated //ToDo verify Problems view and Arithmetic exception on it + softly.assertAll() } } @ParameterizedTest(name = "Check Generate tests button is disabled in {0} project with unsupported JDK {1}") @MethodSource("unsupportedProjectsProvider") - @Tags(Tag("Java"), Tag("UnitTestBot"), Tag("Negative")) + @Tags(Tag("Java"), Tag("UnitTestBot"), Tag("Negative"), Tag("UI")) fun checkProjectWithUnsupportedJDK(ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, remoteRobot: RemoteRobot) { val createdProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number @@ -63,6 +67,8 @@ class UnitTestBotActionTest : BaseTest() { } val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) return with (ideaFrame) { + waitProjectIsOpened() + expandProjectTree() val newClassName = "Arithmetic" createNewJavaClass(newClassName, "Main") textEditor().typeAdditionFunction(newClassName) From c6479e2bad747cbf2a904c62aede216654f9f23c Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Mon, 25 Sep 2023 16:23:50 +0300 Subject: [PATCH 02/16] UI tests optimizations --- .../utbot/data/{RunInfo.kt => RunDetails.kt} | 2 +- .../test/kotlin/org/utbot/tests/BaseTest.kt | 102 ++++++------------ .../kotlin/org/utbot/tests/CreateProjects.kt | 2 +- .../org/utbot/tests/SpringUTBotActionTest.kt | 21 ++-- 4 files changed, 48 insertions(+), 79 deletions(-) rename utbot-intellij/src/test/kotlin/org/utbot/data/{RunInfo.kt => RunDetails.kt} (84%) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt b/utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt similarity index 84% rename from utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt rename to utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt index fe379aa9ac..735c383f83 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt @@ -7,6 +7,6 @@ import java.util.Random val TEST_RUN_NUMBER: String = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))!! const val DEFAULT_TEST_GENERATION_TIMEOUT = 60L val NEW_PROJECT_NAME_START = "Aut_${TEST_RUN_NUMBER}_" -const val DEFAULT_PROJECT_DIRECTORY = "~\\IdeaProjects" +const val DEFAULT_PROJECT_DIRECTORY = "D:\\\\JavaProjects\\\\Autotests\\\\" const val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" val random: Random = Random() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt index b64969ce77..6873dd924b 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt @@ -1,20 +1,20 @@ package org.utbot.tests import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.utils.waitFor import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.extension.ExtendWith import org.junit.jupiter.params.provider.Arguments import org.utbot.data.IdeaBuildSystem import org.utbot.data.JDKVersion -import org.utbot.data.NEW_PROJECT_NAME_START import org.utbot.pages.* import org.utbot.utils.RemoteRobotExtension import org.utbot.utils.StepsLogger import java.time.Duration.ofSeconds +@TestInstance(TestInstance.Lifecycle.PER_CLASS) @ExtendWith(RemoteRobotExtension::class) open class BaseTest { fun getIdeaFrameForBuildSystem(remoteRobot: RemoteRobot, ideaBuildSystem: IdeaBuildSystem): IdeaFrame { @@ -25,6 +25,11 @@ open class BaseTest { } } + @BeforeAll + fun init(remoteRobot: RemoteRobot) { + StepsLogger.init() + } + @BeforeEach fun `Close each project before test`(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { try { @@ -41,77 +46,40 @@ open class BaseTest { } } - fun createProjectWithJDK( - projectName:String = "", - ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, - remoteRobot: RemoteRobot - ) { - var newProjectName = projectName - if (projectName == "") { - newProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number - } - remoteRobot.welcomeFrame { - createNewProject( - newProjectName, - buildSystem = ideaBuildSystem, - jdkVersion = jdkVersion - ) - } - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) - with(ideaFrame) { - waitProjectIsCreated() - waitFor(ofSeconds(30)) { - !isDumbMode() - } - } - } - - companion object { - @BeforeAll - @JvmStatic - fun init(remoteRobot: RemoteRobot) { - StepsLogger.init() - } - - internal val supportedProjectsList: List = - addPairsToList(true) - private val unsupportedProjectsList: List = - addPairsToList(false) + internal val supportedProjectsList: List = + addPairsToList(true) + private val unsupportedProjectsList: List = + addPairsToList(false) - @JvmStatic - fun supportedProjectsProvider(): List { - return supportedProjectsList - } + fun supportedProjectsProvider(): List { + return supportedProjectsList + } - @JvmStatic - fun unsupportedProjectsProvider(): List { - return unsupportedProjectsList - } + fun unsupportedProjectsProvider(): List { + return unsupportedProjectsList + } - @JvmStatic - fun allProjectsProvider(): List { - return supportedProjectsList + unsupportedProjectsList - } + fun allProjectsProvider(): List { + return supportedProjectsList + unsupportedProjectsList + } - @JvmStatic - private fun addPairsToList(supported: Boolean): List { - val ideaBuildSystems = IdeaBuildSystem.values() - ideaBuildSystems.shuffle() - var j = 0 + private fun addPairsToList(supported: Boolean): List { + val ideaBuildSystems = IdeaBuildSystem.values() + ideaBuildSystems.shuffle() + var j = 0 - val listOfArguments: MutableList = mutableListOf() - JDKVersion.values().toMutableList().filter { - it.supported == supported - }.forEach { - listOfArguments.add( - Arguments.of(ideaBuildSystems[j], it) //each (un)supported JDK with a random build system - ) - j++ - if (j >= ideaBuildSystems.size) { - j = 0 - } + val listOfArguments: MutableList = mutableListOf() + JDKVersion.values().toMutableList().filter { + it.supported == supported + }.forEach { + listOfArguments.add( + Arguments.of(ideaBuildSystems[j], it) //each (un)supported JDK with a random build system + ) + j++ + if (j >= ideaBuildSystems.size) { + j = 0 } - return listOfArguments } + return listOfArguments } } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index eee5299898..c5b9c6fcac 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -18,7 +18,7 @@ class CreateProjects : BaseTest() { @ParameterizedTest(name = "Create {0} project with JDK {1}") @Tags(Tag("smoke"), Tag("NewProject"), Tag("Java"), Tag("UTBot"), Tag("")) @MethodSource("allProjectsProvider") - fun createProjectWithSupportedJDK( + fun createProjectWithJDK( ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, remoteRobot: RemoteRobot ): Unit = with(remoteRobot) { diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index 27b7b48f9f..3a1dd7e651 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -5,27 +5,30 @@ import com.intellij.remoterobot.utils.waitForIgnoringError import org.assertj.core.api.SoftAssertions import org.junit.jupiter.api.* import org.utbot.data.IdeaBuildSystem +import org.utbot.pages.IdeaGradleFrame +import org.utbot.pages.idea import org.utbot.pages.welcomeFrame import java.time.Duration class SpringUTBotActionTest : BaseTest() { - val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" + val SPRING_PROJECT_DIRECTORY = "D:\\\\JavaProjects\\\\spring\\\\" + val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" val APP_PACKAGE_NAME = "org.springframework.samples.petclinic" val EXISTING_PACKAGE_NAME = "vet" val EXISTING_CLASS_NAME = "VetController" @BeforeEach - fun openExistingSpringProject (remoteRobot: RemoteRobot) { - remoteRobot.welcomeFrame { + fun openExistingSpringProject(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { + welcomeFrame { try { findText(SPRING_EXISTING_PROJECT_NAME).click() } catch (ignore: NoSuchElementException) { openProjectByPath(SPRING_PROJECT_DIRECTORY, SPRING_EXISTING_PROJECT_NAME) } } - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) - return with (ideaFrame) { + val ideaFrame = remoteRobot.find(IdeaGradleFrame::class.java, Duration.ofSeconds(10)) + return with(ideaFrame) { waitProjectIsOpened() expandProjectTree() } @@ -133,7 +136,7 @@ class SpringUTBotActionTest : BaseTest() { waitForIgnoringError (Duration.ofSeconds(5)){ inlineProgressTextPanel.isShowing } - waitForIgnoringError (Duration.ofSeconds(60)){ + waitForIgnoringError (Duration.ofSeconds(30)){ inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") } waitForIgnoringError(Duration.ofSeconds(60)) { @@ -152,11 +155,9 @@ class SpringUTBotActionTest : BaseTest() { } } - @AfterEach - fun closeDialogIfNotClosed (remoteRobot: RemoteRobot) { - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) - with (ideaFrame) { + fun closeDialogIfNotClosed (remoteRobot: RemoteRobot): Unit = with(remoteRobot){ + idea { try { unitTestBotDialog.closeButton.click() } catch (ignore: Throwable) {} From 93fc34b03b06ad67a38cd5470305ff2abce5d522 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Fri, 29 Sep 2023 17:20:39 +0300 Subject: [PATCH 03/16] InspectionViewFixture added + several corrections --- .../test/kotlin/org/utbot/data/RunDetails.kt | 2 +- .../utbot/dialogs/NewProjectDialogFixture.kt | 8 +- .../utbot/dialogs/UnitTestBotDialogFixture.kt | 4 +- .../test/kotlin/org/utbot/pages/IdeaFrame.kt | 11 ++- .../kotlin/org/utbot/pages/WelcomeFrame.kt | 4 +- .../org/utbot/tabs/InspectionViewFixture.kt | 16 ++++ .../test/kotlin/org/utbot/tests/BaseTest.kt | 73 ++++++++++--------- .../kotlin/org/utbot/tests/CreateProjects.kt | 4 +- .../org/utbot/tests/SpringUTBotActionTest.kt | 42 ++++++----- 9 files changed, 98 insertions(+), 66 deletions(-) create mode 100644 utbot-intellij/src/test/kotlin/org/utbot/tabs/InspectionViewFixture.kt diff --git a/utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt b/utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt index 735c383f83..d0be3a7ec7 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt @@ -7,6 +7,6 @@ import java.util.Random val TEST_RUN_NUMBER: String = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))!! const val DEFAULT_TEST_GENERATION_TIMEOUT = 60L val NEW_PROJECT_NAME_START = "Aut_${TEST_RUN_NUMBER}_" -const val DEFAULT_PROJECT_DIRECTORY = "D:\\\\JavaProjects\\\\Autotests\\\\" +const val DEFAULT_PROJECT_DIRECTORY = "D:\\JavaProjects\\Autotests" const val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" val random: Random = Random() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt index 1ddc6660cc..d9a9e48cb2 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt @@ -82,15 +82,11 @@ class NewProjectDialogFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteC nameInput.doubleClick() keyboard.hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_A) keyboard.enterText(projectName) - var input = DEFAULT_PROJECT_DIRECTORY - if (location != "") { - input = location - } - if (locationInput.hasText(input).not()) { + if (locationInput.hasText(location).not()) { locationInput.click() keyboard{ hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_A) - enterText(input.replace("\\", "\\\\")) + enterText(location.replace("\\", "\\\\")) } } this.findText(language).click() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt index 9d6975f02d..323c44f6b9 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt @@ -98,11 +98,11 @@ class UnitTestBotDialogFixture( val springTestsTypeLabel get() = jLabel( - byXpath("//div[@text='Tests type:']")) + byXpath("//div[@text='Test type:']")) val springTestsTypeComboBox get() = comboBox( - byXpath("//div[@accessiblename='Tests type:' and @class='ComboBox']")) + byXpath("//div[@accessiblename='Test type:' and @class='ComboBox']")) val springActiveProfilesLabel get() = jLabel( diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt index e0efef997b..c65a3df6ab 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt @@ -13,6 +13,7 @@ import org.utbot.data.IdeaBuildSystem import org.utbot.dialogs.UnitTestBotDialogFixture import org.utbot.dialogs.WarningDialogFixture import org.utbot.elements.NotificationFixture +import org.utbot.tabs.InspectionViewFixture import java.awt.event.KeyEvent import java.time.Duration import java.time.Duration.ofSeconds @@ -63,8 +64,14 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) ofSeconds(10)) val unitTestBotDialog - get() = remoteRobot.find(UnitTestBotDialogFixture::class.java, - ofSeconds(10)) + get() = remoteRobot.find(UnitTestBotDialogFixture::class.java) + + val inspectionsView + get() = remoteRobot.find(InspectionViewFixture::class.java) + + val hideInspectionViewButton + get() = actionButton( byXpath("//div[@text.key='toolwindow.stripe.Problems_View']"), + Duration.ofSeconds(5)) @JvmOverloads fun dumbAware(timeout: Duration = Duration.ofMinutes(5), function: () -> Unit) { diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt index 1e46cd7611..4b6e00851b 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt @@ -39,9 +39,9 @@ class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : get() = remoteRobot.find(NewProjectDialogFixture::class.java) fun openProjectByPath(location: String, projectName: String = "") { - val localPath = location + projectName + val localPath = location + "\\" + projectName openProjectLink.click() - keyboard.enterText(localPath) + keyboard.enterText(localPath.replace("\\", "\\\\")) openProjectDialog.okButton.click() } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tabs/InspectionViewFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/tabs/InspectionViewFixture.kt new file mode 100644 index 0000000000..b6fc97b370 --- /dev/null +++ b/utbot-intellij/src/test/kotlin/org/utbot/tabs/InspectionViewFixture.kt @@ -0,0 +1,16 @@ +package org.utbot.tabs + +import com.intellij.remoterobot.RemoteRobot +import com.intellij.remoterobot.data.RemoteComponent +import com.intellij.remoterobot.fixtures.* +import com.intellij.remoterobot.search.locators.byXpath +import java.time.Duration.ofSeconds + +@FixtureName("Inspection Results View") +@DefaultXpath("InspectionResultsView type", "//div[@class='InspectionResultsView']") +class InspectionViewFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : CommonContainerFixture(remoteRobot, remoteComponent) { + + val inspectionTree // not all problems, but only inspections tab + get() = find(byXpath("//div[@class='InspectionTree']"), + ofSeconds(10)) +} diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt index 6873dd924b..becf8db9eb 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/BaseTest.kt @@ -25,11 +25,6 @@ open class BaseTest { } } - @BeforeAll - fun init(remoteRobot: RemoteRobot) { - StepsLogger.init() - } - @BeforeEach fun `Close each project before test`(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { try { @@ -46,40 +41,52 @@ open class BaseTest { } } - internal val supportedProjectsList: List = - addPairsToList(true) - private val unsupportedProjectsList: List = - addPairsToList(false) + companion object { + @BeforeAll + @JvmStatic + fun init(remoteRobot: RemoteRobot) { + StepsLogger.init() + } - fun supportedProjectsProvider(): List { - return supportedProjectsList - } + internal val supportedProjectsList: List = + addPairsToList(true) + private val unsupportedProjectsList: List = + addPairsToList(false) - fun unsupportedProjectsProvider(): List { - return unsupportedProjectsList - } + @JvmStatic + fun supportedProjectsProvider(): List { + return supportedProjectsList + } - fun allProjectsProvider(): List { - return supportedProjectsList + unsupportedProjectsList - } + @JvmStatic + fun unsupportedProjectsProvider(): List { + return unsupportedProjectsList + } + + @JvmStatic + fun allProjectsProvider(): List { + return supportedProjectsList + unsupportedProjectsList + } - private fun addPairsToList(supported: Boolean): List { - val ideaBuildSystems = IdeaBuildSystem.values() - ideaBuildSystems.shuffle() - var j = 0 + @JvmStatic + private fun addPairsToList(supported: Boolean): List { + val ideaBuildSystems = IdeaBuildSystem.values() + ideaBuildSystems.shuffle() + var j = 0 - val listOfArguments: MutableList = mutableListOf() - JDKVersion.values().toMutableList().filter { - it.supported == supported - }.forEach { - listOfArguments.add( - Arguments.of(ideaBuildSystems[j], it) //each (un)supported JDK with a random build system - ) - j++ - if (j >= ideaBuildSystems.size) { - j = 0 + val listOfArguments: MutableList = mutableListOf() + JDKVersion.values().toMutableList().filter { + it.supported == supported + }.forEach { + listOfArguments.add( + Arguments.of(ideaBuildSystems[j], it) //each (un)supported JDK with a random build system + ) + j++ + if (j >= ideaBuildSystems.size) { + j = 0 + } } + return listOfArguments } - return listOfArguments } } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index c5b9c6fcac..afbe65ff60 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Tags import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource +import org.utbot.data.DEFAULT_PROJECT_DIRECTORY import org.utbot.data.IdeaBuildSystem import org.utbot.data.JDKVersion import org.utbot.data.NEW_PROJECT_NAME_START @@ -27,7 +28,8 @@ class CreateProjects : BaseTest() { createNewProject( projectName = newProjectName, buildSystem = ideaBuildSystem, - jdkVersion = jdkVersion + jdkVersion = jdkVersion, + location = DEFAULT_PROJECT_DIRECTORY ) } val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index 3a1dd7e651..1ce3a52889 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -12,7 +12,7 @@ import java.time.Duration class SpringUTBotActionTest : BaseTest() { - val SPRING_PROJECT_DIRECTORY = "D:\\\\JavaProjects\\\\spring\\\\" + val SPRING_PROJECT_DIRECTORY = "D:\\JavaProjects\\spring" val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" val APP_PACKAGE_NAME = "org.springframework.samples.petclinic" val EXISTING_PACKAGE_NAME = "vet" @@ -133,25 +133,29 @@ class SpringUTBotActionTest : BaseTest() { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") unitTestBotDialog.generateTestsButton.click() - waitForIgnoringError (Duration.ofSeconds(5)){ - inlineProgressTextPanel.isShowing - } - waitForIgnoringError (Duration.ofSeconds(30)){ - inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") - } - waitForIgnoringError(Duration.ofSeconds(60)) { - utbotNotification.title.hasText("UnitTestBot: unit tests generated successfully") - } - val softly = SoftAssertions() - softly.assertThat(utbotNotification.body.hasText("Target: org.springframework.samples.petclinic.vet.VetController Overall test methods: 7")) - softly.assertThat(textEditor().editor.text).contains("class ${EXISTING_CLASS_NAME}Test") - softly.assertThat(textEditor().editor.text).contains("@Test\n") - softly.assertThat(textEditor().editor.text).contains(CONTEXT_LOADS_TEST_TEXT) - softly.assertThat(textEditor().editor.text).contains("@utbot.classUnderTest {@link ${EXISTING_CLASS_NAME}}") - softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${EXISTING_CLASS_NAME}#showResourcesVetList") - softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${EXISTING_CLASS_NAME}#showVetList") - softly.assertAll() } + waitForIgnoringError (Duration.ofSeconds(10)){ + inlineProgressTextPanel.isShowing + } + waitForIgnoringError (Duration.ofSeconds(60)){ + inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") + } + waitForIgnoringError(Duration.ofSeconds(90)) { + utbotNotification.title.hasText("UnitTestBot: unit tests generated successfully") + } + val softly = SoftAssertions() + softly.assertThat(utbotNotification.body.hasText("Target: org.springframework.samples.petclinic.vet.VetController Overall test methods: 7")) + softly.assertThat(textEditor().editor.text).contains("class ${EXISTING_CLASS_NAME}Test") + softly.assertThat(textEditor().editor.text).contains("@Test\n") +// softly.assertThat(textEditor().editor.text).contains(CONTEXT_LOADS_TEST_TEXT) + softly.assertThat(textEditor().editor.text).contains("@utbot.classUnderTest {@link ${EXISTING_CLASS_NAME}}") + softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${EXISTING_CLASS_NAME}#showResourcesVetList") + softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${EXISTING_CLASS_NAME}#showVetList") + softly.assertThat(inspectionsView.inspectionTree.isShowing) + softly.assertThat(inspectionsView.inspectionTree.hasText("Errors detected by UnitTestBot")) + softly.assertThat(inspectionsView.inspectionTree.hasText("${EXISTING_CLASS_NAME}.java")) + hideInspectionViewButton.click() + softly.assertAll() } } From b52778d604f7b7f516565d64e8c8c8dfed999cb0 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Fri, 29 Sep 2023 17:28:30 +0300 Subject: [PATCH 04/16] Rename back --- .../src/test/kotlin/org/utbot/data/{RunDetails.kt => RunInfo.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename utbot-intellij/src/test/kotlin/org/utbot/data/{RunDetails.kt => RunInfo.kt} (100%) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt similarity index 100% rename from utbot-intellij/src/test/kotlin/org/utbot/data/RunDetails.kt rename to utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt From faeac76c6ecf6f4c2a83f43db12ab2ee4e216669 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Fri, 29 Sep 2023 18:51:16 +0300 Subject: [PATCH 05/16] Smoke test on Spring Integration test generation. Corrected test on Spring Unit test generation. Added integrationTestsWarningDialog fixture. --- .../utbot/dialogs/UnitTestBotDialogFixture.kt | 2 + .../org/utbot/dialogs/WarningDialogFixture.kt | 8 ++++ .../org/utbot/tests/SpringUTBotActionTest.kt | 46 ++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt index 323c44f6b9..3907660726 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt @@ -112,4 +112,6 @@ class UnitTestBotDialogFixture( get() = textField( byXpath("//div[@accessiblename='Active profile(s):' and @class='JBTextField']")) + val integrationTestsWarningDialog: WarningDialogFixture + get() = remoteRobot.find(byXpath( "//*[@title.key='warning.severity.capitalized']")) } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/WarningDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/WarningDialogFixture.kt index f5e4a1e651..210d33e687 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/WarningDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/WarningDialogFixture.kt @@ -21,4 +21,12 @@ class WarningDialogFixture( get() = button( byXpath("//div[@text.key='button.cancel']")) + val proceedButton + get() = button( + byXpath("//div[@text='Proceed']")) + + val goBackButton + get() = button( + byXpath("//div[@text='Go Back']")) + } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index 1ce3a52889..6cb1ccf0f1 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -147,7 +147,8 @@ class SpringUTBotActionTest : BaseTest() { softly.assertThat(utbotNotification.body.hasText("Target: org.springframework.samples.petclinic.vet.VetController Overall test methods: 7")) softly.assertThat(textEditor().editor.text).contains("class ${EXISTING_CLASS_NAME}Test") softly.assertThat(textEditor().editor.text).contains("@Test\n") -// softly.assertThat(textEditor().editor.text).contains(CONTEXT_LOADS_TEST_TEXT) + softly.assertThat(textEditor().editor.text).contains("@InjectMocks\n\tprivate VetController vetController;") + softly.assertThat(textEditor().editor.text).contains("@Mock\n\tprivate VetRepository vetRepositoryMock;") softly.assertThat(textEditor().editor.text).contains("@utbot.classUnderTest {@link ${EXISTING_CLASS_NAME}}") softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${EXISTING_CLASS_NAME}#showResourcesVetList") softly.assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${EXISTING_CLASS_NAME}#showVetList") @@ -159,6 +160,49 @@ class SpringUTBotActionTest : BaseTest() { } } + @Test + @DisplayName("Check Spring Integration tests generation") + @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("Integration tests"), Tag("Generate tests")) + fun checkSpringIntegrationTestsGeneration(remoteRobot: RemoteRobot) { + val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) + return with (ideaFrame) { + openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) + with (unitTestBotDialog) { + springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ + heavyWeightWindow().itemsList.clickItem("PetClinicApplication") + springTestsTypeComboBox.selectItem("Integration tests") + unitTestBotDialog.generateTestsButton.click() + unitTestBotDialog.integrationTestsWarningDialog.proceedButton.click() + } + waitForIgnoringError (Duration.ofSeconds(10)){ + inlineProgressTextPanel.isShowing + } + waitForIgnoringError (Duration.ofSeconds(60)){ + inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") + } + waitForIgnoringError(Duration.ofSeconds(90)) { + utbotNotification.title.hasText("UnitTestBot: unit tests generated successfully") + } + val softly = SoftAssertions() + softly.assertThat(utbotNotification.body.hasText("Target: org.springframework.samples.petclinic.vet.VetController Overall test methods: ")) + softly.assertThat(textEditor().editor.text).contains("@SpringBootTest\n") + softly.assertThat(textEditor().editor.text).contains("@BootstrapWith(SpringBootTestContextBootstrapper.class)\n") + softly.assertThat(textEditor().editor.text).contains("@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)\n") + softly.assertThat(textEditor().editor.text).contains("@Transactional\n") + softly.assertThat(textEditor().editor.text).contains("@AutoConfigureTestDatabase\n") + softly.assertThat(textEditor().editor.text).contains("@AutoConfigureMockMvc\n") + softly.assertThat(textEditor().editor.text).contains("class ${EXISTING_CLASS_NAME}Test") + softly.assertThat(textEditor().editor.text).contains("@Test\n") + softly.assertThat(textEditor().editor.text).contains(CONTEXT_LOADS_TEST_TEXT) + softly.assertThat(textEditor().editor.text).contains("///region FUZZER: SUCCESSFUL EXECUTIONS for method showResourcesVetList()") + softly.assertThat(inspectionsView.inspectionTree.isShowing) + softly.assertThat(inspectionsView.inspectionTree.hasText("Errors detected by UnitTestBot")) + softly.assertThat(inspectionsView.inspectionTree.hasText("${EXISTING_CLASS_NAME}.java")) + hideInspectionViewButton.click() + softly.assertAll() + } + } + @AfterEach fun closeDialogIfNotClosed (remoteRobot: RemoteRobot): Unit = with(remoteRobot){ idea { From a146630803504ba7cf0c8ea294fb4e1e689f6e6c Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Mon, 2 Oct 2023 16:58:25 +0300 Subject: [PATCH 06/16] Draft default project directory in TMP folder. And clone spring-petclinic from VCS. --- .../src/test/kotlin/org/utbot/data/RunInfo.kt | 8 ++++++-- .../org/utbot/dialogs/NewProjectDialogFixture.kt | 3 ++- .../test/kotlin/org/utbot/pages/WelcomeFrame.kt | 14 ++++++++++++-- .../org/utbot/tests/SpringUTBotActionTest.kt | 9 +++++---- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt index d0be3a7ec7..1655edb619 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt @@ -1,12 +1,16 @@ package org.utbot.data +import java.io.File import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.Random val TEST_RUN_NUMBER: String = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))!! -const val DEFAULT_TEST_GENERATION_TIMEOUT = 60L val NEW_PROJECT_NAME_START = "Aut_${TEST_RUN_NUMBER}_" -const val DEFAULT_PROJECT_DIRECTORY = "D:\\JavaProjects\\Autotests" + +val tempDirectoryPath: String = System.getProperty("java.io.tmpdir") +val DEFAULT_PROJECT_DIRECTORY = "${tempDirectoryPath + File.separator}Autotests" + const val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" val random: Random = Random() +const val DEFAULT_TEST_GENERATION_TIMEOUT = 60L diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt index d9a9e48cb2..9e075d94b2 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt @@ -12,6 +12,7 @@ import org.utbot.data.DEFAULT_PROJECT_DIRECTORY import org.utbot.data.IdeaBuildSystem import org.utbot.data.JDKVersion import java.awt.event.KeyEvent +import java.io.File import java.time.Duration import java.time.Duration.ofSeconds @@ -86,7 +87,7 @@ class NewProjectDialogFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteC locationInput.click() keyboard{ hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_A) - enterText(location.replace("\\", "\\\\")) + enterText(location.replace(File.separator, File.separator + File.separator)) } } this.findText(language).click() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt index 4b6e00851b..b8da1a0699 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt @@ -9,6 +9,7 @@ import org.utbot.data.IdeaBuildSystem import org.utbot.data.JDKVersion import org.utbot.dialogs.NewProjectDialogFixture import org.utbot.dialogs.OpenProjectDialogFixture +import java.io.File import java.time.Duration fun RemoteRobot.welcomeFrame(function: WelcomeFrame.()-> Unit) { @@ -26,6 +27,8 @@ class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : get() = actionLink(byXpath("New Project","//div[(@class='MainButton' and @text='New Project') or (@accessiblename='New Project' and @class='JButton')]")) val openProjectLink get() = actionLink(byXpath("Open","//div[(@class='MainButton' and @text='Open') or (@accessiblename.key='action.WelcomeScreen.OpenProject.text')]")) + val getFromVSCLink + get() = actionLink(byXpath("Get from VCS","//div[(@class='MainButton' and @text='Get from VCS')]")) val moreActions get() = button(byXpath("More Action", "//div[@accessiblename='More Actions']")) @@ -38,10 +41,13 @@ class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : val newProjectDialog get() = remoteRobot.find(NewProjectDialogFixture::class.java) + + fun openProjectByPath(location: String, projectName: String = "") { - val localPath = location + "\\" + projectName + val separator = File.separator + val localPath = location + separator + projectName openProjectLink.click() - keyboard.enterText(localPath.replace("\\", "\\\\")) + keyboard.enterText(localPath.replace(separator, separator + separator)) openProjectDialog.okButton.click() } @@ -56,4 +62,8 @@ class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : ) newProjectDialog.createButton.click() } + + fun cloneProjectFromVC(url: String, buildSystem: IdeaBuildSystem) { + + } } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index 6cb1ccf0f1..f22c58e458 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -4,16 +4,17 @@ import com.intellij.remoterobot.RemoteRobot import com.intellij.remoterobot.utils.waitForIgnoringError import org.assertj.core.api.SoftAssertions import org.junit.jupiter.api.* +import org.utbot.data.DEFAULT_PROJECT_DIRECTORY import org.utbot.data.IdeaBuildSystem +import org.utbot.data.SPRING_EXISTING_PROJECT_NAME import org.utbot.pages.IdeaGradleFrame import org.utbot.pages.idea import org.utbot.pages.welcomeFrame +import java.io.File import java.time.Duration class SpringUTBotActionTest : BaseTest() { - val SPRING_PROJECT_DIRECTORY = "D:\\JavaProjects\\spring" - val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" val APP_PACKAGE_NAME = "org.springframework.samples.petclinic" val EXISTING_PACKAGE_NAME = "vet" val EXISTING_CLASS_NAME = "VetController" @@ -22,9 +23,9 @@ class SpringUTBotActionTest : BaseTest() { fun openExistingSpringProject(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { welcomeFrame { try { - findText(SPRING_EXISTING_PROJECT_NAME).click() + findText(DEFAULT_PROJECT_DIRECTORY + File.separator + SPRING_EXISTING_PROJECT_NAME).click() } catch (ignore: NoSuchElementException) { - openProjectByPath(SPRING_PROJECT_DIRECTORY, SPRING_EXISTING_PROJECT_NAME) + openProjectByPath(DEFAULT_PROJECT_DIRECTORY, SPRING_EXISTING_PROJECT_NAME) } } val ideaFrame = remoteRobot.find(IdeaGradleFrame::class.java, Duration.ofSeconds(10)) From bd20fea1e0688b1e4c5e5481393a4b6344a6d10e Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Mon, 9 Oct 2023 12:05:46 +0300 Subject: [PATCH 07/16] readme.md correction of how to run autotests in utbot-intellij --- utbot-intellij/readme.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utbot-intellij/readme.md b/utbot-intellij/readme.md index 1cab7af388..6f4fe7a37f 100644 --- a/utbot-intellij/readme.md +++ b/utbot-intellij/readme.md @@ -14,8 +14,12 @@ To compile plugin: ## UnitTestBot Intellij Plugin UI Tests -* Comment `exclude("/org/utbot/**")` in utbot-intellij/build.gradle.kts +* comment `exclude("/org/utbot/**")` in utbot-intellij/build.gradle.kts +* correct DEFAULT_PROJECT_DIRECTORY in RunInfo.kt if needed (it is your local directory in which test projects will be created locally) * run IDEA in sandbox with IntelliJ Robot server plugin installed: `gradle runIdeForUiTests` +* wait till debug IDEA is started +* check it is above other windows and maximized +* check keyboard language is EN * run **All** the tests in utbot-intellij/src/test/kotlin/org/utbot/tests Note: projects are created first and only on new projects tests are executed. From 96a772f24e1fb2284187a6f820d930281ac5a691 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Mon, 9 Oct 2023 17:19:48 +0300 Subject: [PATCH 08/16] Current version of UI tests --- utbot-intellij/readme.md | 1 + .../src/test/kotlin/org/utbot/data/RunInfo.kt | 14 +++--- .../GetFromVersionControlDialogFixture.kt | 44 +++++++++++++++++++ .../utbot/dialogs/NewProjectDialogFixture.kt | 1 - .../OpenOrImportProjectDialogFixture.kt | 36 +++++++++++++++ .../dialogs/ProjectStructureDialogFixture.kt | 36 +++++++++++++++ .../kotlin/org/utbot/pages/IdeaGradleFrame.kt | 6 +-- .../kotlin/org/utbot/pages/WelcomeFrame.kt | 21 ++++++--- .../kotlin/org/utbot/tests/CreateProjects.kt | 13 +++--- .../org/utbot/tests/SpringUTBotActionTest.kt | 34 +++++++------- .../kotlin/org/utbot/tests/UTBotActionTest.kt | 27 +++++++----- 11 files changed, 184 insertions(+), 49 deletions(-) create mode 100644 utbot-intellij/src/test/kotlin/org/utbot/dialogs/GetFromVersionControlDialogFixture.kt create mode 100644 utbot-intellij/src/test/kotlin/org/utbot/dialogs/OpenOrImportProjectDialogFixture.kt create mode 100644 utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt diff --git a/utbot-intellij/readme.md b/utbot-intellij/readme.md index 6f4fe7a37f..55b6a3c3ab 100644 --- a/utbot-intellij/readme.md +++ b/utbot-intellij/readme.md @@ -20,6 +20,7 @@ To compile plugin: * wait till debug IDEA is started * check it is above other windows and maximized * check keyboard language is EN +* do NOT lock screen * run **All** the tests in utbot-intellij/src/test/kotlin/org/utbot/tests Note: projects are created first and only on new projects tests are executed. diff --git a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt index 1655edb619..4e89fba84e 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt @@ -1,16 +1,20 @@ package org.utbot.data +import org.utbot.common.utBotTempDirectory import java.io.File import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.Random val TEST_RUN_NUMBER: String = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"))!! -val NEW_PROJECT_NAME_START = "Aut_${TEST_RUN_NUMBER}_" -val tempDirectoryPath: String = System.getProperty("java.io.tmpdir") -val DEFAULT_PROJECT_DIRECTORY = "${tempDirectoryPath + File.separator}Autotests" +val tempDirectoryPath: String = utBotTempDirectory.toAbsolutePath().toString() +const val DEFAULT_DIRECTORY_NAME = "Autotests" +val DEFAULT_DIRECTORY_FULL_PATH = tempDirectoryPath + File.separator + DEFAULT_DIRECTORY_NAME +val CURRENT_RUN_DIRECTORY_FULL_PATH = DEFAULT_DIRECTORY_FULL_PATH + File.separator + TEST_RUN_NUMBER +val CURRENT_RUN_DIRECTORY_END = DEFAULT_DIRECTORY_NAME + File.separator + TEST_RUN_NUMBER + +const val SPRING_PROJECT_NAME = "spring-petclinic" +const val SPRING_PROJECT_URL = "https://github.com/spring-projects/spring-petclinic.git" -const val SPRING_EXISTING_PROJECT_NAME = "spring-petclinic" val random: Random = Random() -const val DEFAULT_TEST_GENERATION_TIMEOUT = 60L diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/GetFromVersionControlDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/GetFromVersionControlDialogFixture.kt new file mode 100644 index 0000000000..21509c10ec --- /dev/null +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/GetFromVersionControlDialogFixture.kt @@ -0,0 +1,44 @@ +package org.utbot.dialogs + +import com.intellij.remoterobot.RemoteRobot +import com.intellij.remoterobot.data.RemoteComponent +import com.intellij.remoterobot.fixtures.* +import com.intellij.remoterobot.search.locators.byXpath +import com.intellij.remoterobot.utils.keyboard +import org.utbot.data.IdeaBuildSystem +import java.awt.event.KeyEvent +import java.io.File + +@FixtureName("Get from Version Control Dialog") +@DefaultXpath("Dialog type", "//*[@title.key='get.from.version.control']") +class GetFromVersionControlDialogFixture( + remoteRobot: RemoteRobot, + remoteComponent: RemoteComponent) : DialogFixture(remoteRobot, remoteComponent) { + + val urlInput + get() = textField( + byXpath("//div[@class='BorderlessTextField']")) + + val directoryInput + get() = textField( + byXpath("//div[@class='ExtendableTextField']")) + + val cloneButton + get() = button( + byXpath("//div[@text.key='clone.dialog.clone.button']")) + + val cancelButton + get() = button( + byXpath("//div[@text.key='button.cancel']")) + + fun fillDialog(url: String, location: String = "") { + urlInput.keyboard { enterText(url) } + if (directoryInput.hasText(location).not()) { // firstly change directory, otherwise it won't be updated with project name + directoryInput.click() + keyboard{ + hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_A) + enterText(location.replace(File.separator, File.separator + File.separator)) + } + } + } +} \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt index 9e075d94b2..d5357ff432 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt @@ -8,7 +8,6 @@ import com.intellij.remoterobot.stepsProcessing.step import com.intellij.remoterobot.utils.Keyboard import com.intellij.remoterobot.utils.keyboard import com.intellij.remoterobot.utils.waitForIgnoringError -import org.utbot.data.DEFAULT_PROJECT_DIRECTORY import org.utbot.data.IdeaBuildSystem import org.utbot.data.JDKVersion import java.awt.event.KeyEvent diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/OpenOrImportProjectDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/OpenOrImportProjectDialogFixture.kt new file mode 100644 index 0000000000..90b089c601 --- /dev/null +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/OpenOrImportProjectDialogFixture.kt @@ -0,0 +1,36 @@ +package org.utbot.dialogs + +import com.intellij.remoterobot.RemoteRobot +import com.intellij.remoterobot.data.RemoteComponent +import com.intellij.remoterobot.fixtures.* +import com.intellij.remoterobot.search.locators.byXpath +import com.intellij.remoterobot.utils.waitFor +import org.utbot.data.IdeaBuildSystem +import java.time.Duration + +@FixtureName("Open or Import Project Dialog") +@DefaultXpath("Dialog type", "//*[@title.key='project.open.select.from.multiple.processors.dialog.title']") +class OpenOrImportProjectDialogFixture( + remoteRobot: RemoteRobot, + remoteComponent: RemoteComponent) : DialogFixture(remoteRobot, remoteComponent) { + + val openAsRadioButtons + get() = radioButtons( + byXpath("//div[@class='JBRadioButton']")) + + val okButton + get() = button( + byXpath("//div[@text.key='button.ok']")) + + val cancelButton + get() = button( + byXpath("//div[@text.key='button.cancel']")) + + fun selectBuildSystem(buildSystem: IdeaBuildSystem) { + waitFor { + openAsRadioButtons.isNotEmpty() + } + openAsRadioButtons.first { it.text.contains(buildSystem.system) } + okButton.click() + } +} \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt new file mode 100644 index 0000000000..257ac2bf2e --- /dev/null +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt @@ -0,0 +1,36 @@ +package org.utbot.dialogs + +import com.intellij.remoterobot.RemoteRobot +import com.intellij.remoterobot.data.RemoteComponent +import com.intellij.remoterobot.fixtures.* +import com.intellij.remoterobot.search.locators.byXpath +import com.intellij.remoterobot.utils.waitFor +import com.intellij.remoterobot.utils.waitForIgnoringError +import org.utbot.data.IdeaBuildSystem +import org.utbot.data.JDKVersion +import java.time.Duration + +@FixtureName("Project Structure Dialog") +@DefaultXpath("Dialog type", "//*[@title.key='project.settings.display.name']") +class ProjectStructureDialogFixture( + remoteRobot: RemoteRobot, + remoteComponent: RemoteComponent) : DialogFixture(remoteRobot, remoteComponent) { + + val moduleSdkCombobox + get() = comboBox( + byXpath("//div[@text.key='module.libraries.target.jdk.module.radio']/../div[@class='JdkComboBox']")) + + val okButton + get() = button( + byXpath("//div[@text.key='button.ok']")) + + fun changeModuleSkd(jdkVersion: JDKVersion) { + moduleSdkCombobox.click() + var jdkMatching = jdkVersion.namePart + waitForIgnoringError(Duration.ofSeconds(5)) { + heavyWeightWindow().itemsList.isShowing + } + heavyWeightWindow().itemsList.clickItem(jdkVersion.namePart, fullMatch = false) + } + +} \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt index 8f2ec29a69..a92bc76f95 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt @@ -14,7 +14,7 @@ class IdeaGradleFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent override fun waitProjectIsCreated() { super.waitProjectIsOpened() - repeat (120) { + waitForIgnoringError (ofSeconds(60)) { inlineProgressTextPanel.isShowing.not() } } @@ -22,13 +22,13 @@ class IdeaGradleFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent override fun expandProjectTree() { with(projectViewTree) { waitForIgnoringError(ofSeconds(10)) { - hasText("src") + hasText(projectName) } if (hasText("src").not()) { findText(projectName).doubleClick() } waitForIgnoringError{ - hasText("main") + hasText("src") } if (hasText("main").not()) { findText("src").doubleClick() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt index b8da1a0699..54d924420b 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt @@ -7,7 +7,9 @@ import com.intellij.remoterobot.search.locators.byXpath import com.intellij.remoterobot.utils.Keyboard import org.utbot.data.IdeaBuildSystem import org.utbot.data.JDKVersion +import org.utbot.dialogs.GetFromVersionControlDialogFixture import org.utbot.dialogs.NewProjectDialogFixture +import org.utbot.dialogs.OpenOrImportProjectDialogFixture import org.utbot.dialogs.OpenProjectDialogFixture import java.io.File import java.time.Duration @@ -35,13 +37,18 @@ class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : val recentProjectLinks get() = jTree(byXpath("//div[@class='CardLayoutPanel']//div[@class='Tree']")) - val openProjectDialog - get() = remoteRobot.find(OpenProjectDialogFixture::class.java) - val newProjectDialog get() = remoteRobot.find(NewProjectDialogFixture::class.java) + val openProjectDialog + get() = remoteRobot.find(OpenProjectDialogFixture::class.java) + + val getFromVersionControlDialog + get() = remoteRobot.find(GetFromVersionControlDialogFixture::class.java) + val openOrImportProjectDialog + get() = remoteRobot.find(OpenOrImportProjectDialogFixture::class.java, + Duration.ofSeconds(120)) fun openProjectByPath(location: String, projectName: String = "") { val separator = File.separator @@ -63,7 +70,11 @@ class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : newProjectDialog.createButton.click() } - fun cloneProjectFromVC(url: String, buildSystem: IdeaBuildSystem) { - + fun cloneProjectFromVC(url: String, location: String = "", + buildSystem: IdeaBuildSystem) { + getFromVSCLink.click() + getFromVersionControlDialog.fillDialog(url, location) + getFromVersionControlDialog.cloneButton.click() + openOrImportProjectDialog.selectBuildSystem(buildSystem) } } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index afbe65ff60..1c47353930 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -7,10 +7,7 @@ import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Tags import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource -import org.utbot.data.DEFAULT_PROJECT_DIRECTORY -import org.utbot.data.IdeaBuildSystem -import org.utbot.data.JDKVersion -import org.utbot.data.NEW_PROJECT_NAME_START +import org.utbot.data.* import org.utbot.pages.welcomeFrame import java.time.Duration @@ -22,18 +19,18 @@ class CreateProjects : BaseTest() { fun createProjectWithJDK( ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, remoteRobot: RemoteRobot - ): Unit = with(remoteRobot) { - val newProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number + ) { + val newProjectName = ideaBuildSystem.system + jdkVersion.number remoteRobot.welcomeFrame { createNewProject( projectName = newProjectName, buildSystem = ideaBuildSystem, jdkVersion = jdkVersion, - location = DEFAULT_PROJECT_DIRECTORY + location = CURRENT_RUN_DIRECTORY_FULL_PATH ) } val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) - with(ideaFrame) { + return with(ideaFrame) { waitProjectIsCreated() waitFor(Duration.ofSeconds(30)) { !isDumbMode() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index f22c58e458..df93569b27 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -4,9 +4,7 @@ import com.intellij.remoterobot.RemoteRobot import com.intellij.remoterobot.utils.waitForIgnoringError import org.assertj.core.api.SoftAssertions import org.junit.jupiter.api.* -import org.utbot.data.DEFAULT_PROJECT_DIRECTORY -import org.utbot.data.IdeaBuildSystem -import org.utbot.data.SPRING_EXISTING_PROJECT_NAME +import org.utbot.data.* import org.utbot.pages.IdeaGradleFrame import org.utbot.pages.idea import org.utbot.pages.welcomeFrame @@ -18,21 +16,32 @@ class SpringUTBotActionTest : BaseTest() { val APP_PACKAGE_NAME = "org.springframework.samples.petclinic" val EXISTING_PACKAGE_NAME = "vet" val EXISTING_CLASS_NAME = "VetController" + val randomBuildSystem = if (random.nextBoolean()) IdeaBuildSystem.MAVEN else IdeaBuildSystem.GRADLE @BeforeEach - fun openExistingSpringProject(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { + fun openSpringProject(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { welcomeFrame { try { - findText(DEFAULT_PROJECT_DIRECTORY + File.separator + SPRING_EXISTING_PROJECT_NAME).click() - } catch (ignore: NoSuchElementException) { - openProjectByPath(DEFAULT_PROJECT_DIRECTORY, SPRING_EXISTING_PROJECT_NAME) + findText { + it.text.endsWith(CURRENT_RUN_DIRECTORY_END + File.separator + SPRING_PROJECT_NAME) + }.click() + } catch (ignore: NoSuchElementException) { // ToDo move to CreateProjects + cloneProjectFromVC( + SPRING_PROJECT_URL, + CURRENT_RUN_DIRECTORY_FULL_PATH + File.separator + SPRING_PROJECT_NAME, + randomBuildSystem) } } - val ideaFrame = remoteRobot.find(IdeaGradleFrame::class.java, Duration.ofSeconds(10)) - return with(ideaFrame) { - waitProjectIsOpened() + with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) {//this particular project has gradle default structure + waitProjectIsCreated() expandProjectTree() + openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) + with (unitTestBotDialog) { // ToDo move to CreateProjects + setupSdkLink.click() + + } } + return } @Test @@ -41,7 +50,6 @@ class SpringUTBotActionTest : BaseTest() { fun checkSpringDefaultActionDialog(remoteRobot: RemoteRobot) { val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) return with (ideaFrame) { - openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) with (unitTestBotDialog) { val softly = SoftAssertions() softly.assertThat(springConfigurationLabel.isVisible()) @@ -84,7 +92,6 @@ class SpringUTBotActionTest : BaseTest() { fun checkActionDialogWithSpringConfiguration(remoteRobot: RemoteRobot) { val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) return with (ideaFrame) { - openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -106,7 +113,6 @@ class SpringUTBotActionTest : BaseTest() { fun checkActionDialogWithIntegrationTests(remoteRobot: RemoteRobot) { val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) return with (ideaFrame) { - openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -129,7 +135,6 @@ class SpringUTBotActionTest : BaseTest() { fun checkSpringUnitTestsGeneration(remoteRobot: RemoteRobot) { val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) return with (ideaFrame) { - openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -167,7 +172,6 @@ class SpringUTBotActionTest : BaseTest() { fun checkSpringIntegrationTestsGeneration(remoteRobot: RemoteRobot) { val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) return with (ideaFrame) { - openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt index 081a387ec3..9d140022de 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt @@ -4,16 +4,17 @@ import com.intellij.remoterobot.RemoteRobot import com.intellij.remoterobot.utils.waitForIgnoringError import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.SoftAssertions +import org.jetbrains.kotlin.konan.file.File import org.junit.jupiter.api.* import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource -import org.utbot.data.IdeaBuildSystem -import org.utbot.data.JDKVersion -import org.utbot.data.NEW_PROJECT_NAME_START +import org.utbot.data.* +import org.utbot.data.TEST_RUN_NUMBER import org.utbot.pages.* import org.utbot.samples.typeAdditionFunction import org.utbot.samples.typeDivisionFunction import java.time.Duration.ofSeconds +import java.util.function.Predicate class UTBotActionTest : BaseTest() { @ParameterizedTest(name = "Generate tests in {0} project with JDK {1}") @@ -21,12 +22,13 @@ class UTBotActionTest : BaseTest() { @Tags(Tag("Java"), Tag("UnitTestBot"), Tag("Positive"), Tag("Generate tests")) fun checkBasicTestGeneration(ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, remoteRobot: RemoteRobot) { - val createdProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number + val createdProjectName = ideaBuildSystem.system + jdkVersion.number remoteRobot.welcomeFrame { - findText(createdProjectName).click() + findText { + it.text.endsWith(CURRENT_RUN_DIRECTORY_END + File.separator + createdProjectName) + }.click() } - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) - with (ideaFrame) { + return with (getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem)) { waitProjectIsOpened() expandProjectTree() val newClassName = "Arithmetic" @@ -61,12 +63,13 @@ class UTBotActionTest : BaseTest() { @Tags(Tag("Java"), Tag("UnitTestBot"), Tag("Negative"), Tag("UI")) fun checkProjectWithUnsupportedJDK(ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, remoteRobot: RemoteRobot) { - val createdProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number + val createdProjectName = ideaBuildSystem.system + jdkVersion.number remoteRobot.welcomeFrame { - findText(createdProjectName).click() + findText { + it.text.endsWith(CURRENT_RUN_DIRECTORY_END + File.separator + createdProjectName) + }.click() } - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) - return with (ideaFrame) { + return with (getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem)) { waitProjectIsOpened() expandProjectTree() val newClassName = "Arithmetic" @@ -74,7 +77,7 @@ class UTBotActionTest : BaseTest() { textEditor().typeAdditionFunction(newClassName) openUTBotDialogFromProjectViewForClass(newClassName) assertThat(unitTestBotDialog.generateTestsButton.isEnabled().not()) - assertThat(unitTestBotDialog.sdkNotificationLabel.hasText("SDK version 19 is not supported, use 1.8, 11 or 17 instead.")) + assertThat(unitTestBotDialog.sdkNotificationLabel.hasText("SDK version ${jdkVersion.number} is not supported, use 1.8, 11 or 17 instead.")) assertThat(unitTestBotDialog.setupSdkLink.isShowing) unitTestBotDialog.closeButton.click() } From d812d26b68b985557c408bcec3d621ce7eeab509 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Tue, 10 Oct 2023 18:58:17 +0300 Subject: [PATCH 09/16] Spring UI tests updates - draft Change location only if not containing current run id folder Add files to git dialog --- .../src/test/kotlin/org/utbot/data/RunInfo.kt | 2 + .../dialogs/AddFileToGitDialogFixture.kt | 20 ++++++ .../utbot/dialogs/NewProjectDialogFixture.kt | 4 +- .../OpenOrImportProjectDialogFixture.kt | 4 +- .../dialogs/ProjectStructureDialogFixture.kt | 12 ++-- .../utbot/dialogs/UnitTestBotDialogFixture.kt | 2 +- .../test/kotlin/org/utbot/pages/IdeaFrame.kt | 34 +++++++--- .../kotlin/org/utbot/pages/IdeaGradleFrame.kt | 4 +- .../kotlin/org/utbot/pages/IdeaMavenFrame.kt | 4 +- .../kotlin/org/utbot/pages/WelcomeFrame.kt | 4 +- .../kotlin/org/utbot/tests/CreateProjects.kt | 31 ++++++++- .../org/utbot/tests/SpringUTBotActionTest.kt | 63 +++++++++---------- .../kotlin/org/utbot/tests/UTBotActionTest.kt | 6 +- 13 files changed, 128 insertions(+), 62 deletions(-) create mode 100644 utbot-intellij/src/test/kotlin/org/utbot/dialogs/AddFileToGitDialogFixture.kt diff --git a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt index 4e89fba84e..75076f3376 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt @@ -18,3 +18,5 @@ const val SPRING_PROJECT_NAME = "spring-petclinic" const val SPRING_PROJECT_URL = "https://github.com/spring-projects/spring-petclinic.git" val random: Random = Random() +val springProjectBuildSystem = if (random.nextBoolean()) + IdeaBuildSystem.MAVEN else IdeaBuildSystem.GRADLE diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/AddFileToGitDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/AddFileToGitDialogFixture.kt new file mode 100644 index 0000000000..32c0f25842 --- /dev/null +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/AddFileToGitDialogFixture.kt @@ -0,0 +1,20 @@ +package org.utbot.dialogs + +import com.intellij.remoterobot.RemoteRobot +import com.intellij.remoterobot.data.RemoteComponent +import com.intellij.remoterobot.fixtures.* +import com.intellij.remoterobot.search.locators.byXpath +import com.intellij.remoterobot.utils.waitFor +import org.utbot.data.IdeaBuildSystem +import java.time.Duration + +@FixtureName("Add File to Git Dialog") +@DefaultXpath("Dialog type", "//*[@title.key='vfs.listener.add.single.title']") +class AddFileToGitDialogFixture( + remoteRobot: RemoteRobot, + remoteComponent: RemoteComponent) : DialogFixture(remoteRobot, remoteComponent) { + + val cancelButton + get() = button( + byXpath("//div[@text.key='button.cancel']")) +} \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt index d5357ff432..277b033e20 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/NewProjectDialogFixture.kt @@ -73,7 +73,7 @@ class NewProjectDialogFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteC } fun fillDialog(projectName: String, - location: String = "", + location: String = "", locationPart: String = "", language: String = "Java", buildSystem: IdeaBuildSystem = IdeaBuildSystem.INTELLIJ, jdkVersion: JDKVersion, @@ -82,7 +82,7 @@ class NewProjectDialogFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteC nameInput.doubleClick() keyboard.hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_A) keyboard.enterText(projectName) - if (locationInput.hasText(location).not()) { + if (!locationInput.hasText{it.text.contains(locationPart)}) { locationInput.click() keyboard{ hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_A) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/OpenOrImportProjectDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/OpenOrImportProjectDialogFixture.kt index 90b089c601..c96e3e3dde 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/OpenOrImportProjectDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/OpenOrImportProjectDialogFixture.kt @@ -30,7 +30,9 @@ class OpenOrImportProjectDialogFixture( waitFor { openAsRadioButtons.isNotEmpty() } - openAsRadioButtons.first { it.text.contains(buildSystem.system) } + openAsRadioButtons.filter { + it.text.contains(buildSystem.system) + }[0].click() okButton.click() } } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt index 257ac2bf2e..9ab9a1201e 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt @@ -4,9 +4,7 @@ import com.intellij.remoterobot.RemoteRobot import com.intellij.remoterobot.data.RemoteComponent import com.intellij.remoterobot.fixtures.* import com.intellij.remoterobot.search.locators.byXpath -import com.intellij.remoterobot.utils.waitFor import com.intellij.remoterobot.utils.waitForIgnoringError -import org.utbot.data.IdeaBuildSystem import org.utbot.data.JDKVersion import java.time.Duration @@ -16,6 +14,10 @@ class ProjectStructureDialogFixture( remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : DialogFixture(remoteRobot, remoteComponent) { + val projectJdkCombobox + get() = comboBox( + byXpath("//div[@class='JdkComboBox']")) + val moduleSdkCombobox get() = comboBox( byXpath("//div[@text.key='module.libraries.target.jdk.module.radio']/../div[@class='JdkComboBox']")) @@ -24,9 +26,9 @@ class ProjectStructureDialogFixture( get() = button( byXpath("//div[@text.key='button.ok']")) - fun changeModuleSkd(jdkVersion: JDKVersion) { - moduleSdkCombobox.click() - var jdkMatching = jdkVersion.namePart + fun setProjectSdk(jdkVersion: JDKVersion) { + findText("Project").click() + projectJdkCombobox.click() waitForIgnoringError(Duration.ofSeconds(5)) { heavyWeightWindow().itemsList.isShowing } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt index 3907660726..587ae6c071 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt @@ -113,5 +113,5 @@ class UnitTestBotDialogFixture( byXpath("//div[@accessiblename='Active profile(s):' and @class='JBTextField']")) val integrationTestsWarningDialog: WarningDialogFixture - get() = remoteRobot.find(byXpath( "//*[@title.key='warning.severity.capitalized']")) + get() = remoteRobot.find(byXpath( "//*[contains(@title.key,'warning.severity.capitalized')]")) } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt index c65a3df6ab..500810851c 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt @@ -10,6 +10,8 @@ import com.intellij.remoterobot.utils.waitFor import com.intellij.remoterobot.utils.waitForIgnoringError import org.assertj.swing.core.MouseButton import org.utbot.data.IdeaBuildSystem +import org.utbot.dialogs.AddFileToGitDialogFixture +import org.utbot.dialogs.ProjectStructureDialogFixture import org.utbot.dialogs.UnitTestBotDialogFixture import org.utbot.dialogs.WarningDialogFixture import org.utbot.elements.NotificationFixture @@ -63,15 +65,21 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) get() = remoteRobot.find(byXpath( "//div[@class='NotificationCenterPanel'][div[contains(.,'UnitTestBot')]]"), ofSeconds(10)) + val inspectionsView + get() = remoteRobot.find(InspectionViewFixture::class.java) + + val problemsTabButton + get() = button( byXpath("//div[contains(@text.key, 'toolwindow.stripe.Problems_View')]")) + + // Dialogs val unitTestBotDialog get() = remoteRobot.find(UnitTestBotDialogFixture::class.java) - val inspectionsView - get() = remoteRobot.find(InspectionViewFixture::class.java) + val projectStructureDialog + get() = remoteRobot.find(ProjectStructureDialogFixture::class.java) - val hideInspectionViewButton - get() = actionButton( byXpath("//div[@text.key='toolwindow.stripe.Problems_View']"), - Duration.ofSeconds(5)) + val addFileToGitDialog + get() = remoteRobot.find(AddFileToGitDialogFixture::class.java) @JvmOverloads fun dumbAware(timeout: Duration = Duration.ofMinutes(5), function: () -> Unit) { @@ -129,7 +137,7 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) } } - open fun waitProjectIsOpened() { + open fun waitProjectIsBuilt() { projectViewTree.click() keyboard { key(KeyEvent.VK_PAGE_UP) } waitForIgnoringError(ofSeconds(30)) { @@ -138,7 +146,7 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) } open fun waitProjectIsCreated() { - waitProjectIsOpened() + waitProjectIsBuilt() } open fun expandProjectTree() { @@ -180,4 +188,16 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) enter() } } + + fun openProjectStructureDialog() { + if (remoteRobot.isMac()) { + keyboard { + hotKey(KeyEvent.VK_SHIFT, KeyEvent.VK_META, KeyEvent.VK_A) + enterText("Project Structure...") + enter() + } + } else { + menuBar.select("File", "Project Structure...") + } + } } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt index a92bc76f95..22a8137c52 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt @@ -13,8 +13,8 @@ class IdeaGradleFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent override val buildSystemToUse = IdeaBuildSystem.GRADLE override fun waitProjectIsCreated() { - super.waitProjectIsOpened() - waitForIgnoringError (ofSeconds(60)) { + super.waitProjectIsBuilt() + repeat (120) { inlineProgressTextPanel.isShowing.not() } } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaMavenFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaMavenFrame.kt index f3fbe39805..c555880aa5 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaMavenFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaMavenFrame.kt @@ -12,8 +12,8 @@ class IdeaMavenFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) override val buildSystemToUse = IdeaBuildSystem.MAVEN - override fun waitProjectIsOpened() { - super.waitProjectIsOpened() + override fun waitProjectIsBuilt() { + super.waitProjectIsBuilt() waitForIgnoringError (ofSeconds(60)) { projectViewTree.hasText("Main.java").not() projectViewTree.hasText("Main") diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt index 54d924420b..987085e6ae 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/WelcomeFrame.kt @@ -58,13 +58,13 @@ class WelcomeFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) : openProjectDialog.okButton.click() } - fun createNewProject(projectName: String, location: String = "", + fun createNewProject(projectName: String, location: String = "", locationPart: String = "", language: String = "Java", buildSystem: IdeaBuildSystem = IdeaBuildSystem.INTELLIJ, jdkVersion: JDKVersion, addSampleCode: Boolean = true) { newProjectLink.click() newProjectDialog.selectWizard("New Project") newProjectDialog.fillDialog( - projectName, location, language, + projectName, location, locationPart, language, buildSystem, jdkVersion, addSampleCode ) newProjectDialog.createButton.click() diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index 1c47353930..158118a9ca 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -2,19 +2,23 @@ package org.utbot.tests import com.intellij.remoterobot.RemoteRobot import com.intellij.remoterobot.utils.waitFor +import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Order import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Tags +import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource import org.utbot.data.* +import org.utbot.pages.idea import org.utbot.pages.welcomeFrame +import java.io.File import java.time.Duration @Order(1) class CreateProjects : BaseTest() { @ParameterizedTest(name = "Create {0} project with JDK {1}") - @Tags(Tag("smoke"), Tag("NewProject"), Tag("Java"), Tag("UTBot"), Tag("")) + @Tags(Tag("Setup"), Tag("Java"), Tag("UTBot")) @MethodSource("allProjectsProvider") fun createProjectWithJDK( ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion, @@ -26,7 +30,8 @@ class CreateProjects : BaseTest() { projectName = newProjectName, buildSystem = ideaBuildSystem, jdkVersion = jdkVersion, - location = CURRENT_RUN_DIRECTORY_FULL_PATH + location = CURRENT_RUN_DIRECTORY_FULL_PATH, + locationPart = CURRENT_RUN_DIRECTORY_END ) } val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) @@ -37,4 +42,26 @@ class CreateProjects : BaseTest() { } } } + + @Test + @DisplayName("Clone Spring project") + @Tags(Tag("Setup"), Tag("Java"), Tag("Spring"), Tag("UTBot")) + fun cloneSpringProject(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { + welcomeFrame { + cloneProjectFromVC( + SPRING_PROJECT_URL, + CURRENT_RUN_DIRECTORY_FULL_PATH + File.separator + SPRING_PROJECT_NAME, + springProjectBuildSystem + ) + } + with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { + waitProjectIsBuilt() + expandProjectTree() //this particular project has gradle default structure + } + idea { + openProjectStructureDialog() + projectStructureDialog.setProjectSdk(JDKVersion.JDK_17) + projectStructureDialog.okButton.click() + } + } } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index df93569b27..f55b4b7bbd 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -1,45 +1,37 @@ package org.utbot.tests import com.intellij.remoterobot.RemoteRobot +import com.intellij.remoterobot.utils.keyboard import com.intellij.remoterobot.utils.waitForIgnoringError import org.assertj.core.api.SoftAssertions import org.junit.jupiter.api.* import org.utbot.data.* -import org.utbot.pages.IdeaGradleFrame import org.utbot.pages.idea import org.utbot.pages.welcomeFrame -import java.io.File +import java.awt.event.KeyEvent import java.time.Duration class SpringUTBotActionTest : BaseTest() { - val APP_PACKAGE_NAME = "org.springframework.samples.petclinic" val EXISTING_PACKAGE_NAME = "vet" val EXISTING_CLASS_NAME = "VetController" - val randomBuildSystem = if (random.nextBoolean()) IdeaBuildSystem.MAVEN else IdeaBuildSystem.GRADLE @BeforeEach fun openSpringProject(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { welcomeFrame { - try { - findText { - it.text.endsWith(CURRENT_RUN_DIRECTORY_END + File.separator + SPRING_PROJECT_NAME) - }.click() - } catch (ignore: NoSuchElementException) { // ToDo move to CreateProjects - cloneProjectFromVC( - SPRING_PROJECT_URL, - CURRENT_RUN_DIRECTORY_FULL_PATH + File.separator + SPRING_PROJECT_NAME, - randomBuildSystem) - } + findText { + it.text.endsWith(SPRING_PROJECT_NAME) + }.click() } - with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) {//this particular project has gradle default structure - waitProjectIsCreated() + with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { + keyboard { + hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_F9) + } + waitProjectIsBuilt() expandProjectTree() + } + idea { openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) - with (unitTestBotDialog) { // ToDo move to CreateProjects - setupSdkLink.click() - - } } return } @@ -48,8 +40,7 @@ class SpringUTBotActionTest : BaseTest() { @DisplayName("Check action dialog UI default state in a Spring project") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) fun checkSpringDefaultActionDialog(remoteRobot: RemoteRobot) { - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) - return with (ideaFrame) { + return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { with (unitTestBotDialog) { val softly = SoftAssertions() softly.assertThat(springConfigurationLabel.isVisible()) @@ -90,8 +81,7 @@ class SpringUTBotActionTest : BaseTest() { @DisplayName("Check action dialog UI when Spring configuration is selected") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) fun checkActionDialogWithSpringConfiguration(remoteRobot: RemoteRobot) { - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) - return with (ideaFrame) { + return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -111,8 +101,7 @@ class SpringUTBotActionTest : BaseTest() { @DisplayName("Check action dialog UI when Integration tests are selected") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) fun checkActionDialogWithIntegrationTests(remoteRobot: RemoteRobot) { - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) - return with (ideaFrame) { + return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -133,8 +122,7 @@ class SpringUTBotActionTest : BaseTest() { @DisplayName("Check Spring Unit tests generation") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("Unit tests"), Tag("Generate tests")) fun checkSpringUnitTestsGeneration(remoteRobot: RemoteRobot) { - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) - return with (ideaFrame) { + return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -147,7 +135,11 @@ class SpringUTBotActionTest : BaseTest() { inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") } waitForIgnoringError(Duration.ofSeconds(90)) { - utbotNotification.title.hasText("UnitTestBot: unit tests generated successfully") + if (addFileToGitDialog.isShowing) { + addFileToGitDialog.cancelButton.click() + } + utbotNotification.title.hasText("UnitTestBot: unit tests generated with warnings") + // because project has several test frameworks } val softly = SoftAssertions() softly.assertThat(utbotNotification.body.hasText("Target: org.springframework.samples.petclinic.vet.VetController Overall test methods: 7")) @@ -161,7 +153,7 @@ class SpringUTBotActionTest : BaseTest() { softly.assertThat(inspectionsView.inspectionTree.isShowing) softly.assertThat(inspectionsView.inspectionTree.hasText("Errors detected by UnitTestBot")) softly.assertThat(inspectionsView.inspectionTree.hasText("${EXISTING_CLASS_NAME}.java")) - hideInspectionViewButton.click() + problemsTabButton.click() softly.assertAll() } } @@ -170,8 +162,7 @@ class SpringUTBotActionTest : BaseTest() { @DisplayName("Check Spring Integration tests generation") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("Integration tests"), Tag("Generate tests")) fun checkSpringIntegrationTestsGeneration(remoteRobot: RemoteRobot) { - val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE) - return with (ideaFrame) { + return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -186,7 +177,11 @@ class SpringUTBotActionTest : BaseTest() { inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") } waitForIgnoringError(Duration.ofSeconds(90)) { - utbotNotification.title.hasText("UnitTestBot: unit tests generated successfully") + if (addFileToGitDialog.isShowing) { + addFileToGitDialog.cancelButton.click() + } + utbotNotification.title.hasText("UnitTestBot: unit tests generated with warnings") + // because project has several test frameworks } val softly = SoftAssertions() softly.assertThat(utbotNotification.body.hasText("Target: org.springframework.samples.petclinic.vet.VetController Overall test methods: ")) @@ -203,7 +198,7 @@ class SpringUTBotActionTest : BaseTest() { softly.assertThat(inspectionsView.inspectionTree.isShowing) softly.assertThat(inspectionsView.inspectionTree.hasText("Errors detected by UnitTestBot")) softly.assertThat(inspectionsView.inspectionTree.hasText("${EXISTING_CLASS_NAME}.java")) - hideInspectionViewButton.click() + problemsTabButton.click() softly.assertAll() } } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt index 9d140022de..497d6911fe 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/UTBotActionTest.kt @@ -9,12 +9,10 @@ import org.junit.jupiter.api.* import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource import org.utbot.data.* -import org.utbot.data.TEST_RUN_NUMBER import org.utbot.pages.* import org.utbot.samples.typeAdditionFunction import org.utbot.samples.typeDivisionFunction import java.time.Duration.ofSeconds -import java.util.function.Predicate class UTBotActionTest : BaseTest() { @ParameterizedTest(name = "Generate tests in {0} project with JDK {1}") @@ -29,7 +27,7 @@ class UTBotActionTest : BaseTest() { }.click() } return with (getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem)) { - waitProjectIsOpened() + waitProjectIsBuilt() expandProjectTree() val newClassName = "Arithmetic" createNewJavaClass(newClassName, "Main") @@ -70,7 +68,7 @@ class UTBotActionTest : BaseTest() { }.click() } return with (getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem)) { - waitProjectIsOpened() + waitProjectIsBuilt() expandProjectTree() val newClassName = "Arithmetic" createNewJavaClass(newClassName, "Main") From 6f36d6facb9ebe5f006385372e116c7711162831 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Wed, 11 Oct 2023 19:32:39 +0300 Subject: [PATCH 10/16] Spring UI tests updated and stabilized --- .../src/test/kotlin/org/utbot/data/RunInfo.kt | 2 -- .../dialogs/ProjectStructureDialogFixture.kt | 6 +++- .../utbot/dialogs/UnitTestBotDialogFixture.kt | 2 +- .../org/utbot/elements/NotificationFixture.kt | 13 +++++-- .../test/kotlin/org/utbot/pages/IdeaFrame.kt | 20 +++++++---- .../kotlin/org/utbot/pages/IdeaGradleFrame.kt | 11 +++--- .../kotlin/org/utbot/tests/CreateProjects.kt | 15 ++++---- .../org/utbot/tests/SpringUTBotActionTest.kt | 36 +++++++++---------- 8 files changed, 61 insertions(+), 44 deletions(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt index 75076f3376..4e89fba84e 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/data/RunInfo.kt @@ -18,5 +18,3 @@ const val SPRING_PROJECT_NAME = "spring-petclinic" const val SPRING_PROJECT_URL = "https://github.com/spring-projects/spring-petclinic.git" val random: Random = Random() -val springProjectBuildSystem = if (random.nextBoolean()) - IdeaBuildSystem.MAVEN else IdeaBuildSystem.GRADLE diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt index 9ab9a1201e..3df95ce70d 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/ProjectStructureDialogFixture.kt @@ -4,6 +4,7 @@ import com.intellij.remoterobot.RemoteRobot import com.intellij.remoterobot.data.RemoteComponent import com.intellij.remoterobot.fixtures.* import com.intellij.remoterobot.search.locators.byXpath +import com.intellij.remoterobot.utils.keyboard import com.intellij.remoterobot.utils.waitForIgnoringError import org.utbot.data.JDKVersion import java.time.Duration @@ -32,7 +33,10 @@ class ProjectStructureDialogFixture( waitForIgnoringError(Duration.ofSeconds(5)) { heavyWeightWindow().itemsList.isShowing } - heavyWeightWindow().itemsList.clickItem(jdkVersion.namePart, fullMatch = false) + keyboard { + enterText(jdkVersion.namePart) + enter() + } } } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt index 587ae6c071..2d256cff99 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/dialogs/UnitTestBotDialogFixture.kt @@ -113,5 +113,5 @@ class UnitTestBotDialogFixture( byXpath("//div[@accessiblename='Active profile(s):' and @class='JBTextField']")) val integrationTestsWarningDialog: WarningDialogFixture - get() = remoteRobot.find(byXpath( "//*[contains(@title.key,'warning.severity.capitalized')]")) + get() = remoteRobot.find(byXpath( "//div[@title='Warning']")) } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/elements/NotificationFixture.kt b/utbot-intellij/src/test/kotlin/org/utbot/elements/NotificationFixture.kt index 5683f12db5..1ba3205e88 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/elements/NotificationFixture.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/elements/NotificationFixture.kt @@ -21,8 +21,15 @@ class NotificationFixture(remoteRobot: RemoteRobot, remoteComponent: RemoteCompo get() = remoteRobot.find(byXpath("//div[@class='JEditorPane']"), ofSeconds(5)) - val link - get() = remoteRobot.find(byXpath("//div[@class='LinkLabel']"), - ofSeconds(5)) + val projectLoadButton + get() = button(byXpath("//div[@text.key='unlinked.project.notification.load.action']")) + + // For add file to Git notification + val alwaysAddButton + get() = button(byXpath("//div[contains(@text.key, 'external.files.add.notification.action.add')]")) + + val dontAskAgainButton + get() = button(byXpath("//div[contains(@text.key, 'external.files.add.notification.action.mute')]")) + } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt index 500810851c..7b0a16b750 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt @@ -43,7 +43,7 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) val inlineProgressTextPanel get() = remoteRobot.find(byXpath("//div[@class='InlineProgressPanel']//div[@class='TextPanel']"), - ofSeconds(10)) + ofSeconds(5)) val statusTextPanel get() = remoteRobot.find(byXpath("//div[@class='StatusPanel']//div[@class='TextPanel']"), @@ -57,14 +57,23 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) get() = textField(byXpath("//div[contains(@accessiblename.key, 'editor.accessible.name')]"), ofSeconds(20)) + // Notifications val ideError get() = remoteRobot.find(byXpath( "//div[@class='NotificationCenterPanel'][.//div[@accessiblename.key='error.new.notification.title']]"), ofSeconds(10)) val utbotNotification - get() = remoteRobot.find(byXpath( "//div[@class='NotificationCenterPanel'][div[contains(.,'UnitTestBot')]]"), + get() = remoteRobot.find(byXpath( "//div[@class='NotificationCenterPanel' and contains(.,'UnitTestBot')]"), ofSeconds(10)) + val loadProjectNotification + get() = remoteRobot.find(byXpath( "//div[@class='NotificationActionPanel' and contains(.,'Load')]"), + ofSeconds(60)) + + val addToGitNotification + get() = remoteRobot.find(byXpath( "//div[@class='NotificationCenterPanel' and contains(.,'Git')]"), + ofSeconds(60)) + val inspectionsView get() = remoteRobot.find(InspectionViewFixture::class.java) @@ -143,10 +152,9 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) waitForIgnoringError(ofSeconds(30)) { projectViewTree.hasText(projectName) } - } - - open fun waitProjectIsCreated() { - waitProjectIsBuilt() + waitFor(Duration.ofSeconds(30)) { + !isDumbMode() + } } open fun expandProjectTree() { diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt index 22a8137c52..b6aed74418 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt @@ -3,6 +3,7 @@ package org.utbot.pages import com.intellij.remoterobot.RemoteRobot import com.intellij.remoterobot.data.RemoteComponent import com.intellij.remoterobot.fixtures.DefaultXpath +import com.intellij.remoterobot.utils.waitFor import com.intellij.remoterobot.utils.waitForIgnoringError import org.utbot.data.IdeaBuildSystem import java.time.Duration.ofSeconds @@ -12,11 +13,13 @@ class IdeaGradleFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent override val buildSystemToUse = IdeaBuildSystem.GRADLE - override fun waitProjectIsCreated() { + override fun waitProjectIsBuilt() { super.waitProjectIsBuilt() - repeat (120) { - inlineProgressTextPanel.isShowing.not() - } + try { + waitFor (ofSeconds(30)) { + inlineProgressTextPanel.isShowing.not() + } + } catch (ignore: Throwable) {} } override fun expandProjectTree() { diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index 158118a9ca..82c190c623 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -10,7 +10,6 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource import org.utbot.data.* -import org.utbot.pages.idea import org.utbot.pages.welcomeFrame import java.io.File import java.time.Duration @@ -36,7 +35,7 @@ class CreateProjects : BaseTest() { } val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) return with(ideaFrame) { - waitProjectIsCreated() + waitProjectIsBuilt() waitFor(Duration.ofSeconds(30)) { !isDumbMode() } @@ -51,17 +50,19 @@ class CreateProjects : BaseTest() { cloneProjectFromVC( SPRING_PROJECT_URL, CURRENT_RUN_DIRECTORY_FULL_PATH + File.separator + SPRING_PROJECT_NAME, - springProjectBuildSystem + IdeaBuildSystem.MAVEN ) } with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { - waitProjectIsBuilt() - expandProjectTree() //this particular project has gradle default structure - } - idea { + if (loadProjectNotification.isShowing) { + loadProjectNotification.projectLoadButton.click() + waitProjectIsBuilt() + } openProjectStructureDialog() projectStructureDialog.setProjectSdk(JDKVersion.JDK_17) projectStructureDialog.okButton.click() + waitProjectIsBuilt() + expandProjectTree() } } } \ No newline at end of file diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index f55b4b7bbd..8d8047f45e 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -1,14 +1,13 @@ package org.utbot.tests import com.intellij.remoterobot.RemoteRobot -import com.intellij.remoterobot.utils.keyboard import com.intellij.remoterobot.utils.waitForIgnoringError import org.assertj.core.api.SoftAssertions import org.junit.jupiter.api.* import org.utbot.data.* import org.utbot.pages.idea import org.utbot.pages.welcomeFrame -import java.awt.event.KeyEvent +import java.io.File import java.time.Duration class SpringUTBotActionTest : BaseTest() { @@ -20,27 +19,25 @@ class SpringUTBotActionTest : BaseTest() { fun openSpringProject(remoteRobot: RemoteRobot): Unit = with(remoteRobot) { welcomeFrame { findText { - it.text.endsWith(SPRING_PROJECT_NAME) + it.text.endsWith(CURRENT_RUN_DIRECTORY_END + File.separator + SPRING_PROJECT_NAME) }.click() } with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { - keyboard { - hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_F9) - } waitProjectIsBuilt() + if (loadProjectNotification.isShowing) { + loadProjectNotification.projectLoadButton.click() + waitProjectIsBuilt() + } expandProjectTree() - } - idea { openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) } - return } @Test @DisplayName("Check action dialog UI default state in a Spring project") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) fun checkSpringDefaultActionDialog(remoteRobot: RemoteRobot) { - return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { + with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { with (unitTestBotDialog) { val softly = SoftAssertions() softly.assertThat(springConfigurationLabel.isVisible()) @@ -81,7 +78,7 @@ class SpringUTBotActionTest : BaseTest() { @DisplayName("Check action dialog UI when Spring configuration is selected") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) fun checkActionDialogWithSpringConfiguration(remoteRobot: RemoteRobot) { - return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { + with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -101,7 +98,7 @@ class SpringUTBotActionTest : BaseTest() { @DisplayName("Check action dialog UI when Integration tests are selected") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("UI")) fun checkActionDialogWithIntegrationTests(remoteRobot: RemoteRobot) { - return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { + with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -118,11 +115,12 @@ class SpringUTBotActionTest : BaseTest() { } } + @Order(1) // to close git notification @Test @DisplayName("Check Spring Unit tests generation") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("Unit tests"), Tag("Generate tests")) fun checkSpringUnitTestsGeneration(remoteRobot: RemoteRobot) { - return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { + with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -134,10 +132,11 @@ class SpringUTBotActionTest : BaseTest() { waitForIgnoringError (Duration.ofSeconds(60)){ inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") } + waitForIgnoringError (Duration.ofSeconds(90)){ + addToGitNotification.isShowing + } + addToGitNotification.alwaysAddButton.click() // otherwise prompt dialog will be shown for each created test file waitForIgnoringError(Duration.ofSeconds(90)) { - if (addFileToGitDialog.isShowing) { - addFileToGitDialog.cancelButton.click() - } utbotNotification.title.hasText("UnitTestBot: unit tests generated with warnings") // because project has several test frameworks } @@ -162,7 +161,7 @@ class SpringUTBotActionTest : BaseTest() { @DisplayName("Check Spring Integration tests generation") @Tags(Tag("Spring"), Tag("Java"), Tag("UnitTestBot"), Tag("Integration tests"), Tag("Generate tests")) fun checkSpringIntegrationTestsGeneration(remoteRobot: RemoteRobot) { - return with (getIdeaFrameForBuildSystem(remoteRobot, springProjectBuildSystem)) { + with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { with (unitTestBotDialog) { springConfigurationComboBox.click() /* ComboBoxFixture::selectItem doesn't work with heavyWeightWindow */ heavyWeightWindow().itemsList.clickItem("PetClinicApplication") @@ -177,9 +176,6 @@ class SpringUTBotActionTest : BaseTest() { inlineProgressTextPanel.hasText("Generate test cases for class $EXISTING_CLASS_NAME") } waitForIgnoringError(Duration.ofSeconds(90)) { - if (addFileToGitDialog.isShowing) { - addFileToGitDialog.cancelButton.click() - } utbotNotification.title.hasText("UnitTestBot: unit tests generated with warnings") // because project has several test frameworks } From 97960159aa5581439c8e9b2ff4523f1d54043084 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Thu, 12 Oct 2023 10:58:18 +0300 Subject: [PATCH 11/16] Fixes --- utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt | 4 ++-- .../src/test/kotlin/org/utbot/tests/CreateProjects.kt | 2 +- .../src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt index 7b0a16b750..b32bb0664c 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt @@ -68,11 +68,11 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) val loadProjectNotification get() = remoteRobot.find(byXpath( "//div[@class='NotificationActionPanel' and contains(.,'Load')]"), - ofSeconds(60)) + ofSeconds(10)) val addToGitNotification get() = remoteRobot.find(byXpath( "//div[@class='NotificationCenterPanel' and contains(.,'Git')]"), - ofSeconds(60)) + ofSeconds(10)) val inspectionsView get() = remoteRobot.find(InspectionViewFixture::class.java) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index 82c190c623..12f37b3159 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -16,7 +16,7 @@ import java.time.Duration @Order(1) class CreateProjects : BaseTest() { - @ParameterizedTest(name = "Create {0} project with JDK {1}") + //@ParameterizedTest(name = "Create {0} project with JDK {1}") @Tags(Tag("Setup"), Tag("Java"), Tag("UTBot")) @MethodSource("allProjectsProvider") fun createProjectWithJDK( diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index 8d8047f45e..54f6a4c385 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -24,10 +24,10 @@ class SpringUTBotActionTest : BaseTest() { } with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { waitProjectIsBuilt() - if (loadProjectNotification.isShowing) { + try { loadProjectNotification.projectLoadButton.click() waitProjectIsBuilt() - } + } catch (ignore: Throwable) {} expandProjectTree() openUTBotDialogFromProjectViewForClass(EXISTING_CLASS_NAME, EXISTING_PACKAGE_NAME) } From dd0cd6659f66e718e8c6a1937cf97c4fd6b3c8b9 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Thu, 12 Oct 2023 10:58:46 +0300 Subject: [PATCH 12/16] Turn CreateProjects back ON --- .../src/test/kotlin/org/utbot/tests/CreateProjects.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index 12f37b3159..82c190c623 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -16,7 +16,7 @@ import java.time.Duration @Order(1) class CreateProjects : BaseTest() { - //@ParameterizedTest(name = "Create {0} project with JDK {1}") + @ParameterizedTest(name = "Create {0} project with JDK {1}") @Tags(Tag("Setup"), Tag("Java"), Tag("UTBot")) @MethodSource("allProjectsProvider") fun createProjectWithJDK( From e25bdb53aa6314f1a50ea9e139a8abbed0cc6ad5 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Thu, 12 Oct 2023 11:55:15 +0300 Subject: [PATCH 13/16] Exceeded timeouts for project building --- utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt | 2 +- .../src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt | 2 +- .../src/test/kotlin/org/utbot/tests/CreateProjects.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt index b32bb0664c..6d98076b83 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt @@ -152,7 +152,7 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) waitForIgnoringError(ofSeconds(30)) { projectViewTree.hasText(projectName) } - waitFor(Duration.ofSeconds(30)) { + waitFor(Duration.ofSeconds(90)) { !isDumbMode() } } diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt index b6aed74418..11fe5fdce0 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaGradleFrame.kt @@ -16,7 +16,7 @@ class IdeaGradleFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent override fun waitProjectIsBuilt() { super.waitProjectIsBuilt() try { - waitFor (ofSeconds(30)) { + waitFor (ofSeconds(90)) { inlineProgressTextPanel.isShowing.not() } } catch (ignore: Throwable) {} diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index 82c190c623..27c060e7e7 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -36,7 +36,7 @@ class CreateProjects : BaseTest() { val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem) return with(ideaFrame) { waitProjectIsBuilt() - waitFor(Duration.ofSeconds(30)) { + waitFor(Duration.ofSeconds(90)) { !isDumbMode() } } From b2636e60e086cc7d37207529965dde0858e7a8e6 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Thu, 12 Oct 2023 12:15:44 +0300 Subject: [PATCH 14/16] Added check test class is compilable to Spring Unit and Integration tests --- .../test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt index 54f6a4c385..c38b97b00e 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/SpringUTBotActionTest.kt @@ -152,7 +152,9 @@ class SpringUTBotActionTest : BaseTest() { softly.assertThat(inspectionsView.inspectionTree.isShowing) softly.assertThat(inspectionsView.inspectionTree.hasText("Errors detected by UnitTestBot")) softly.assertThat(inspectionsView.inspectionTree.hasText("${EXISTING_CLASS_NAME}.java")) - problemsTabButton.click() + buildResultInEditor.rightClick() // to check test class is compilable + softly.assertThat(heavyWeightWindow().data.getAll().toString().contains("error").not()) + problemsTabButton.click() //to close problems view softly.assertAll() } } @@ -194,7 +196,9 @@ class SpringUTBotActionTest : BaseTest() { softly.assertThat(inspectionsView.inspectionTree.isShowing) softly.assertThat(inspectionsView.inspectionTree.hasText("Errors detected by UnitTestBot")) softly.assertThat(inspectionsView.inspectionTree.hasText("${EXISTING_CLASS_NAME}.java")) - problemsTabButton.click() + buildResultInEditor.rightClick() // to check test class is compilable + softly.assertThat(heavyWeightWindow().data.getAll().toString().contains("error").not()) + problemsTabButton.click() //to close problems view softly.assertAll() } } From b9ae6818c79333952089f9a7705d7e748171e128 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Thu, 12 Oct 2023 13:50:21 +0300 Subject: [PATCH 15/16] wait loadProjectNotification for 30 sec on Spring project clone --- .../src/test/kotlin/org/utbot/tests/CreateProjects.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index 27c060e7e7..e2b4140ea2 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -54,10 +54,11 @@ class CreateProjects : BaseTest() { ) } with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { - if (loadProjectNotification.isShowing) { - loadProjectNotification.projectLoadButton.click() - waitProjectIsBuilt() + waitFor (Duration.ofSeconds(30)) { + loadProjectNotification.isShowing } + loadProjectNotification.projectLoadButton.click() + waitProjectIsBuilt() openProjectStructureDialog() projectStructureDialog.setProjectSdk(JDKVersion.JDK_17) projectStructureDialog.okButton.click() From 6e6c961083339e2dd565fb5885d67d4aab86b340 Mon Sep 17 00:00:00 2001 From: Alena Lisevych Date: Thu, 12 Oct 2023 13:58:58 +0300 Subject: [PATCH 16/16] fix --- .../src/test/kotlin/org/utbot/pages/IdeaFrame.kt | 2 +- .../src/test/kotlin/org/utbot/tests/CreateProjects.kt | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt index 6d98076b83..ee569961bb 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/pages/IdeaFrame.kt @@ -68,7 +68,7 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent) val loadProjectNotification get() = remoteRobot.find(byXpath( "//div[@class='NotificationActionPanel' and contains(.,'Load')]"), - ofSeconds(10)) + ofSeconds(20)) val addToGitNotification get() = remoteRobot.find(byXpath( "//div[@class='NotificationCenterPanel' and contains(.,'Git')]"), diff --git a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt index e2b4140ea2..82d34b8dbe 100644 --- a/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt +++ b/utbot-intellij/src/test/kotlin/org/utbot/tests/CreateProjects.kt @@ -54,11 +54,10 @@ class CreateProjects : BaseTest() { ) } with (getIdeaFrameForBuildSystem(remoteRobot, IdeaBuildSystem.GRADLE)) { - waitFor (Duration.ofSeconds(30)) { - loadProjectNotification.isShowing - } - loadProjectNotification.projectLoadButton.click() - waitProjectIsBuilt() + try { + loadProjectNotification.projectLoadButton.click() + waitProjectIsBuilt() + } catch (ignore: Throwable) {} openProjectStructureDialog() projectStructureDialog.setProjectSdk(JDKVersion.JDK_17) projectStructureDialog.okButton.click()