Skip to content

Commit

Permalink
IntelliJ plugin UI tests correction for debug IDEA 2023.2 (#2531)
Browse files Browse the repository at this point in the history
* Corrected locators and waiters in IntelliJ robot UI tests (debug IDEA version changed to 2023.2).

* A bit more corrections

---------

Co-authored-by: Vassiliy Kudryashov <[email protected]>
  • Loading branch information
alisevych and Vassiliy-Kudryashov authored Aug 30, 2023
1 parent 1480d4b commit 638f803
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ open class DialogFixture(

val closeButton
get() = button(
byXpath("//div[@class='DialogHeader']//div[@class='JButton']"))
byXpath("//div[@class='DialogRootPane']//div[@class='JButton']"))

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ open class IdeaFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent)
}

fun createNewJavaClass(newClassname: String = "Example",
textToClickOn: String = "org.example") {
textToClickOn: String = "Main") {
waitProjectIsOpened()
expandProjectTree(projectName)
with(projectViewTree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class IdeaGradleFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent

override fun waitProjectIsCreated() {
super.waitProjectIsOpened()
waitForIgnoringError (ofSeconds(60)) {
statusTextPanel.hasText { it.text.contains("Gradle sync finished") }
repeat (120) {
inlineProgressTextPanel.isShowing.not()
}
}

Expand All @@ -42,7 +42,7 @@ class IdeaGradleFrame(remoteRobot: RemoteRobot, remoteComponent: RemoteComponent
hasText("src").and(hasText("main")).and(hasText("java"))
}
}
if (hasText("org.example").not()) {
if (hasText("Main").not()) {
findText("java").doubleClick()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fun TextEditorFixture.typeAdditionFunction(className: String): String {
key(KeyEvent.VK_END)
enterText("{")
enter()
enterText("// UTBot UI ${TEST_RUN_NUMBER} test")
enterText("// Test run ${TEST_RUN_NUMBER}")
enter()
enterText("return a + b;")
}
Expand All @@ -32,7 +32,7 @@ fun TextEditorFixture.typeDivisionFunction(className: String) : String {
key(KeyEvent.VK_END)
enterText("{")
enter()
enterText("// UTBot UI ${TEST_RUN_NUMBER} test")
enterText("// Test run ${TEST_RUN_NUMBER}")
enter()
enterText("return a / b;")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class CreateProjects : BaseTest() {
val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem)
with(ideaFrame) {
waitProjectIsCreated()
if (ideaBuildSystem == IdeaBuildSystem.INTELLIJ) {
createNewPackage("org.example")
}
waitFor(Duration.ofSeconds(30)) {
!isDumbMode()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,59 @@ import org.utbot.data.NEW_PROJECT_NAME_START
import org.utbot.pages.*
import org.utbot.samples.typeAdditionFunction
import org.utbot.samples.typeDivisionFunction
import java.time.Duration.ofMillis
import java.time.Duration.ofSeconds

class UnitTestBotActionTest : BaseTest() {

@ParameterizedTest(name = "Generate tests in {0} project with JDK {1}")
@MethodSource("supportedProjectsProvider")
@Tags(Tag("Java"), Tag("UnitTestBot"), Tag("Positive"))
fun basicTestGeneration(ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion,
remoteRobot: RemoteRobot) : Unit = with(remoteRobot) {
fun checkBasicTestGeneration(ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion,
remoteRobot: RemoteRobot) {
val createdProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number
remoteRobot.welcomeFrame {
findText(createdProjectName).click()
}
val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem)
with (ideaFrame) {
val newClassName = "Arithmetic"
createNewJavaClass(newClassName, "org.example")
createNewJavaClass(newClassName, "Main")
val returnsFromTagBody = textEditor().typeDivisionFunction(newClassName)
openUTBotDialogFromProjectViewForClass(newClassName)
unitTestBotDialog.generateTestsButton.click()
waitForIgnoringError (ofSeconds(5)){
inlineProgressTextPanel.isShowing
}
waitForIgnoringError(ofSeconds(60), ofMillis(100)) {
inlineProgressTextPanel.hasText("Generate tests: read classes")
}
waitForIgnoringError (ofSeconds(30)){
waitForIgnoringError (ofSeconds(90)){
inlineProgressTextPanel.hasText("Generate test cases for class $newClassName")
}
waitForIgnoringError(ofSeconds(60)) { //Can be changed to 60 for a complex class
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}#division(int, int)}")
assertThat(textEditor().editor.text).contains("@utbot.methodUnderTest {@link ${newClassName}#")
assertThat(textEditor().editor.text).contains(returnsFromTagBody)
//ToDo verify how many tests are generated
//ToDo verify Problems view and Arithmetic exception on it
}
}

@ParameterizedTest(name = "Check Generate tests button is disabled in {0} project with unsupported JDK {1}")
@MethodSource("unsupportedProjectsProvider")
@Tags(Tag("Java"), Tag("UnitTestBot"), Tag("Negative"))
fun checkTestGenerationIsUnavailable(ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion,
remoteRobot: RemoteRobot) : Unit = with(remoteRobot) {
fun checkProjectWithUnsupportedJDK(ideaBuildSystem: IdeaBuildSystem, jdkVersion: JDKVersion,
remoteRobot: RemoteRobot) {
val createdProjectName = NEW_PROJECT_NAME_START + ideaBuildSystem.system + jdkVersion.number
remoteRobot.welcomeFrame {
findText(createdProjectName).click()
}
val ideaFrame = getIdeaFrameForBuildSystem(remoteRobot, ideaBuildSystem)
with (ideaFrame) {
return with (ideaFrame) {
val newClassName = "Arithmetic"
createNewJavaClass(newClassName, "org.example")
createNewJavaClass(newClassName, "Main")
textEditor().typeAdditionFunction(newClassName)
openUTBotDialogFromProjectViewForClass(newClassName)
assertThat(unitTestBotDialog.generateTestsButton.isEnabled().not())
Expand Down

0 comments on commit 638f803

Please sign in to comment.