Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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