-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from JetBrains-Research/nikolaisv/ICTL-851
ICTL-851 Add support for JUnit 5 for LLM-based test generation
- Loading branch information
Showing
19 changed files
with
213 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
JUnitRunner/src/main/java/org/jetbrains/research/SingleJUnitTestRunner5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jetbrains.research; | ||
|
||
import org.junit.platform.engine.discovery.MethodSelector; | ||
import org.junit.platform.launcher.Launcher; | ||
import org.junit.platform.launcher.LauncherDiscoveryRequest; | ||
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; | ||
import org.junit.platform.launcher.core.LauncherFactory; | ||
import org.junit.platform.launcher.listeners.SummaryGeneratingListener; | ||
import org.junit.platform.launcher.listeners.TestExecutionSummary; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod; | ||
|
||
public class SingleJUnitTestRunner5 { | ||
public static void main(String... args) { | ||
String classAndMethod = args[0]; | ||
MethodSelector methodSelector = selectMethod(classAndMethod); | ||
LauncherDiscoveryRequest request = | ||
LauncherDiscoveryRequestBuilder.request() | ||
.selectors(methodSelector) | ||
.build(); | ||
|
||
Launcher launcher = LauncherFactory.create(); | ||
SummaryGeneratingListener listener = new SummaryGeneratingListener(); | ||
|
||
launcher.registerTestExecutionListeners(listener); | ||
launcher.execute(request); | ||
|
||
TestExecutionSummary result = listener.getSummary(); | ||
List<TestExecutionSummary.Failure> failures = result.getFailures(); | ||
for (TestExecutionSummary.Failure failure : failures) { | ||
failure.getException().printStackTrace(System.err); | ||
System.err.println("\n ==="); | ||
} | ||
System.exit(result.getTestsFailedCount() == 0 ? 0 : 1); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/kotlin/org/jetbrains/research/testspark/actions/template/ToolPanelFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/org/jetbrains/research/testspark/data/JUnitVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jetbrains.research.testspark.data | ||
|
||
enum class JUnitVersion( | ||
val groupId: String, | ||
val version: Int, | ||
val libJar: Set<String>, | ||
val runWithAnnotationMeta: RunWithAnnotationMeta, | ||
val showName: String = "JUnit $version", | ||
) { | ||
JUnit5( | ||
"org.junit.jupiter", | ||
5, | ||
setOf( | ||
"junit-jupiter-api-5.10.0.jar", | ||
"junit-jupiter-engine-5.10.0.jar", | ||
"junit-platform-commons-1.10.0.jar", | ||
"junit-platform-engine-1.10.0.jar", | ||
"junit-platform-launcher-1.10.0.jar", | ||
), | ||
RunWithAnnotationMeta("ExtendWith", "import org.junit.jupiter.api.extension.ExtendWith;"), | ||
), | ||
JUnit4( | ||
"junit", | ||
4, | ||
setOf("junit-4.13.jar"), | ||
RunWithAnnotationMeta("RunWith", "import org.junit.runner.RunWith;"), | ||
), | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/org/jetbrains/research/testspark/data/RunWithAnnotationMeta.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.jetbrains.research.testspark.data | ||
|
||
data class RunWithAnnotationMeta(val annotationName: String, val import: String) { | ||
|
||
val regex = annotationRegex(annotationName) | ||
|
||
fun extract(line: String): String? { | ||
val detectedRunWith = regex.find(line, startIndex = 0)?.groupValues?.get(0) ?: return null | ||
return detectedRunWith | ||
.split("@$annotationName(")[1] | ||
.split(")")[0] | ||
} | ||
|
||
companion object { | ||
private fun annotationRegex(annotationName: String) = Regex( | ||
pattern = "@$annotationName\\([^)]*\\)", | ||
options = setOf(RegexOption.MULTILINE), | ||
) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/org/jetbrains/research/testspark/display/JUnitCombobox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jetbrains.research.testspark.display | ||
|
||
import com.intellij.openapi.ui.ComboBox | ||
import org.jetbrains.research.testspark.data.JUnitVersion | ||
import java.awt.Component | ||
import javax.swing.DefaultListCellRenderer | ||
import javax.swing.JList | ||
|
||
class JUnitCombobox : ComboBox<JUnitVersion>(JUnitVersion.values()) { | ||
|
||
var detected: JUnitVersion? = null | ||
set(value) { | ||
field = value | ||
value?.let { | ||
this.selectedItem = value | ||
} | ||
} | ||
|
||
init { | ||
renderer = object : DefaultListCellRenderer() { | ||
override fun getListCellRendererComponent( | ||
list: JList<*>?, | ||
value: Any?, | ||
index: Int, | ||
isSelected: Boolean, | ||
cellHasFocus: Boolean, | ||
): Component { | ||
var v = value | ||
if (value is JUnitVersion) { | ||
v = value.showName | ||
if (value == detected) { | ||
v += " (Detected)" | ||
} | ||
} | ||
return super.getListCellRendererComponent(list, v, index, isSelected, cellHasFocus) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.