Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kex Integration #294

Open
wants to merge 57 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b8638f1
minimal attempt to run kex from testspark with harcoded settings
edwin1729 Jul 8, 2024
c27e304
generate Report and series of simplifications for MVP
edwin1729 Jul 12, 2024
3579637
download kex as github release if it doesn't exist
edwin1729 Jul 12, 2024
2081eb7
delete commented code
edwin1729 Jul 12, 2024
0cc6108
use javaparser to merge @before and @after generated methods
edwin1729 Jul 17, 2024
17d1524
compiling tests successfully by adding helper method to TestGenData.o…
edwin1729 Jul 17, 2024
4f39630
fold anything but @Test annotated code, but unfortunately only on UI …
edwin1729 Jul 18, 2024
9276624
remove python dependency by running kex jar directly
edwin1729 Jul 22, 2024
d6cfc9a
use project's java and add version check
edwin1729 Jul 22, 2024
ac07b35
empty implementation of settings classes for kex
edwin1729 Jul 22, 2024
b6e03f9
allow setting kex arguments from kex settings page
edwin1729 Jul 23, 2024
7e882d2
kex test generation for 'method' code type
edwin1729 Jul 23, 2024
237e549
fold all but @Test methods regardless of declaration order
edwin1729 Jul 24, 2024
b766057
remove settings for unsupported kex features
edwin1729 Jul 24, 2024
a94fe4e
empty kex path download to .cache and LOCALAPPDATA in windows
edwin1729 Jul 24, 2024
6081340
folding works even if junit isn't in classpath
edwin1729 Jul 24, 2024
00aff2a
use the the subprocess manager from IJ framework
edwin1729 Jul 26, 2024
6dbb7ba
Merge branch 'edwin1729/improvement/kex-integration-download-to-cache…
edwin1729 Jul 29, 2024
6b502da
fix lint. remove wildcard imports
edwin1729 Aug 7, 2024
801a0c1
from IJ api, provide correct build directory to kex
edwin1729 Aug 7, 2024
fcac3c2
set maxTests displayed and minimizeTestSuite options
edwin1729 Aug 7, 2024
7265945
Merge branch 'development' into edwin1729/improvement/kex-integration
edwin1729 Aug 8, 2024
a120c41
fix code fold to only happen once at the start not every ui update
edwin1729 Aug 8, 2024
5e0715b
error handling for errors in kex process manager
edwin1729 Aug 9, 2024
502b983
fix lint
edwin1729 Aug 9, 2024
5c587a4
provide signatures with FQNs to kex for java
edwin1729 Aug 12, 2024
5dbe080
refactor. extract functons, add comments, remove redundancies
edwin1729 Aug 12, 2024
a729d0a
fix lint
edwin1729 Aug 12, 2024
2af26ac
every option in kex cmd is preceeded by --option
edwin1729 Aug 14, 2024
52f24a0
use kotlin.time.Duration instead of Int
edwin1729 Aug 16, 2024
e220fb2
refactor error handling code, check for non-zero exit code
edwin1729 Aug 16, 2024
49100db
make generated code manipulation more robust
edwin1729 Aug 16, 2024
1767a54
only check if the correct verison of kex exists
edwin1729 Aug 16, 2024
081c4db
make download url a property and version a user setting
edwin1729 Aug 16, 2024
a45e236
support jdk version 8. no --add-opens
edwin1729 Aug 16, 2024
123a404
bump up kex version to 0.0.10
edwin1729 Aug 22, 2024
2eacdcb
Merge branch 'development' into edwin1729/improvement/kex-integration
edwin1729 Aug 23, 2024
8d0d811
allow kex test generation for classes not in a package
edwin1729 Aug 27, 2024
62a967e
null safety while folding helper code
edwin1729 Aug 27, 2024
6932ae3
Merge branch 'development' into edwin1729/improvement/kex-integration
edwin1729 Aug 29, 2024
0244a51
Merge branch 'development' into edwin1729/improvement/kex-integration
edwin1729 Aug 29, 2024
cad29c9
disallow kex and line code type being chosen simultaneously
edwin1729 Aug 29, 2024
7fe2f29
update description tab and README.md with kex
edwin1729 Aug 29, 2024
4a0f075
fix lint
edwin1729 Sep 1, 2024
d4131af
fix run coverage by making method name same as class name
edwin1729 Sep 16, 2024
8c75595
undo mistaken removal of addLanguageTextFieldListener before code fol…
edwin1729 Sep 17, 2024
017e435
Merge branch 'development' into edwin1729/improvement/kex-integration
arksap2002 Sep 18, 2024
489a830
Merge branch 'development' into edwin1729/improvement/kex-integration
arksap2002 Oct 25, 2024
fcff2fe
fix getJavaVersion
arksap2002 Oct 28, 2024
e693fc9
add KexSettingsService to plugin.xml
arksap2002 Nov 4, 2024
80ae1dc
Merge branch 'development' into edwin1729/improvement/kex-integration
arksap2002 Nov 4, 2024
18c7d84
fix DefaultKexSettingsState
arksap2002 Nov 4, 2024
284386a
fix KexSettingsState
arksap2002 Nov 5, 2024
4fbe886
fix Bundles
arksap2002 Nov 5, 2024
9d3c013
Merge branch 'development' into edwin1729/improvement/kex-integration
arksap2002 Nov 7, 2024
3df9117
JUnit version forcing
Hello-zoka Nov 7, 2024
e6dcf12
fix getExceptionData
arksap2002 Nov 8, 2024
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ TestSpark currently supports two test generation strategies:
<li>Generate tests for Java classes, methods, and single lines.</li>
</ul>

<h4>Symbolic execution-based test generation</h4>
<p>For this type of test generation, TestSpark uses <a href="https://github.com/vorpal-research/kex">Kex</a>, supporting symbolic execution for Java Byte Code. </p>
<ul>
<li>Supports up to Java 8 and upwards.</li>
<li>Powered by SMT solvers, it supports really high coverages given larger time frames.</li>
<li>Generated test cases are however not very readable (there are plans to automatically refactor with the help of LLMs).</li>
<li>Generates tests for Java classes and methods.</li>
</ul>

<p>Initially implemented by <a href="https://www.ciselab.nl">CISELab</a> at <a href="https://se.ewi.tudelft.nl">SERG @ TU Delft</a>, TestSpark is currently developed and maintained by <a href="https://lp.jetbrains.com/research/ictl/">ICTL at JetBrains Research</a>.</p>

## <span style="color:crimson; font-size:150%; font-weight:bold"> DISCLAIMER </span>
Expand Down
5 changes: 4 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ dependencies {
// https://gitlab.com/mvysny/konsume-xml
implementation("com.gitlab.mvysny.konsume-xml:konsume-xml:1.0")

// for merging generated kex tests into a single file
implementation("com.github.javaparser:javaparser-core:3.26.1")

// From the jetbrains repository
testImplementation("com.intellij.remoterobot:remote-robot:0.11.13")
testImplementation("com.intellij.remoterobot:remote-fixtures:0.11.13")
Expand Down Expand Up @@ -236,7 +239,7 @@ intellijPlatform {
}
freeArgs = listOf(
"-mute",
"TemplateWordInPluginId,ForbiddenPluginIdPrefix"
"TemplateWordInPluginId,ForbiddenPluginIdPrefix",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class TestGenerationData(
var importsCode: MutableSet<String> = mutableSetOf(),
var packageName: String = "",
var runWith: String = "",
// Modifications to this code in the tool-window editor are forgotten when apply to test suite
var otherInfo: String = "",

// changing parameters with a large prompt
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pluginName = TestSpark
pluginVersion = 0.3.0

evosuiteVersion = 1.0.5
kexVersion = 0.0.8

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class JavaPsiMethodWrapper(private val psiMethod: PsiMethod) : PsiMethodWrapper
override val signature: String
get() = buildSignature(psiMethod)

override val parameterNames: List<String>
get() = psiMethod.parameterList.parameters.map { it.name }

override val parameterTypes: List<String>
get() = psiMethod.parameterList.parameters.map { it.type.canonicalText }

override val returnType: String
get() = psiMethod.returnType?.canonicalText ?: "void"

val parameterList = psiMethod.parameterList

val isConstructor: Boolean = psiMethod.isConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class KotlinPsiMethodWrapper(val psiFunction: KtFunction) : PsiMethodWrapper {
override val signature: String
get() = buildSignature(psiFunction)

override val parameterNames: List<String>
get() = psiFunction.valueParameters.map { it.name ?: "" }

override val parameterTypes: List<String>
get() = psiFunction.valueParameters.map { it.typeReference?.text ?: "Any" }

override val returnType: String
get() = psiFunction.typeReference?.text ?: "Unit"

val parameterList = psiFunction.valueParameterList

val isPrimaryConstructor: Boolean = psiFunction is KtPrimaryConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ interface PsiMethodWrapper {
val name: String
val methodDescriptor: String
val signature: String
val parameterNames: List<String>
val parameterTypes: List<String>
val returnType: String
val text: String?
val containingClass: PsiClassWrapper?
val containingFile: PsiFile?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,26 @@ import org.jetbrains.research.testspark.settings.evosuite.EvoSuiteSettingsState
import org.jetbrains.research.testspark.settings.llm.LLMSettingsState
import org.jetbrains.research.testspark.tools.TestsExecutionResultManager
import org.jetbrains.research.testspark.tools.evosuite.EvoSuite
import org.jetbrains.research.testspark.tools.kex.Kex
import org.jetbrains.research.testspark.tools.llm.Llm
import org.jetbrains.research.testspark.tools.template.Tool
import java.awt.BorderLayout
import java.awt.CardLayout
import java.awt.Component
import java.awt.Dimension
import java.awt.Font
import java.awt.Toolkit
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.swing.Box
import javax.swing.BoxLayout
import javax.swing.ButtonGroup
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JRadioButton
import javax.swing.SwingConstants

/**
* Represents an action to be performed in the TestSpark plugin.
Expand Down Expand Up @@ -110,7 +115,9 @@ class TestSparkAction : AnAction() {

private val llmButton = JRadioButton("<html><b>${Llm().name}</b></html>")
private val evoSuiteButton = JRadioButton("<html><b>${EvoSuite().name}</b></html>")
private val kexButton = JRadioButton("<html><b>${Kex().name}</b></html>")
private val testGeneratorButtonGroup = ButtonGroup()
private val kexForLineCodeTypeErrMsg = JLabel() // The error displayed when if kex and line code type are chosen

private val psiHelper: PsiHelper
get() {
Expand Down Expand Up @@ -203,11 +210,13 @@ class TestSparkAction : AnAction() {

testGeneratorButtonGroup.add(llmButton)
testGeneratorButtonGroup.add(evoSuiteButton)
testGeneratorButtonGroup.add(kexButton)

val testGeneratorPanel = JPanel()
testGeneratorPanel.add(JLabel("Select the test generator:"))
testGeneratorPanel.add(llmButton)
testGeneratorPanel.add(evoSuiteButton)
testGeneratorPanel.add(kexButton)

for ((codeType, codeTypeName) in codeTypes) {
val button = JRadioButton(codeTypeName)
Expand Down Expand Up @@ -236,7 +245,13 @@ class TestSparkAction : AnAction() {
.panel

val nextButtonPanel = JPanel()
nextButtonPanel.layout = BoxLayout(nextButtonPanel, BoxLayout.Y_AXIS)
nextButton.isEnabled = false
nextButton.alignmentX = Component.CENTER_ALIGNMENT
kexForLineCodeTypeErrMsg.alignmentX = Component.CENTER_ALIGNMENT
kexForLineCodeTypeErrMsg.horizontalAlignment = SwingConstants.CENTER
nextButtonPanel.add(kexForLineCodeTypeErrMsg)
nextButtonPanel.add(Box.createVerticalStrut(10)) // Add some space between label and button
nextButtonPanel.add(nextButton)

val cardPanel = JPanel(BorderLayout())
Expand Down Expand Up @@ -267,6 +282,10 @@ class TestSparkAction : AnAction() {
updateNextButton()
}

kexButton.addActionListener {
updateNextButton()
}

for ((_, button) in codeTypeButtons) {
button.addActionListener {
llmSetupPanelFactory.setPromptEditorType(button.text)
Expand All @@ -286,6 +305,8 @@ class TestSparkAction : AnAction() {
cardLayout.next(panel)
cardLayout.next(panel)
pack()
} else if (kexButton.isSelected) {
startKexGeneration()
} else if (evoSuiteButton.isSelected && !evoSuiteSettingsState.evosuiteSetupCheckBoxSelected) {
startEvoSuiteGeneration()
} else {
Expand Down Expand Up @@ -387,6 +408,7 @@ class TestSparkAction : AnAction() {
dispose()
}

private fun startKexGeneration() = startUnitTestGenerationTool(tool = Kex())
private fun startEvoSuiteGeneration() = startUnitTestGenerationTool(tool = EvoSuite())
private fun startLLMGeneration() = startUnitTestGenerationTool(tool = Llm())

Expand All @@ -398,12 +420,23 @@ class TestSparkAction : AnAction() {
* This method should be called whenever the mentioned above buttons are clicked.
*/
private fun updateNextButton() {
val isTestGeneratorButtonGroupSelected = llmButton.isSelected || evoSuiteButton.isSelected
val isTestGeneratorButtonGroupSelected = llmButton.isSelected || evoSuiteButton.isSelected || kexButton.isSelected
val isCodeTypeButtonGroupSelected = codeTypeButtons.any { it.second.isSelected }
nextButton.isEnabled = isTestGeneratorButtonGroupSelected && isCodeTypeButtonGroupSelected
val kexForCodeLineType =
kexButton.isSelected && codeTypeButtons.any { (codeType, button) -> codeType == CodeType.LINE && button.isSelected }
if (kexForCodeLineType) {
kexForLineCodeTypeErrMsg.text =
"<html><b><font color='orange'>* Kex cannot generate tests for a single line. Please change your selection</font></b></html>"
} else {
kexForLineCodeTypeErrMsg.text = ""
}

nextButton.isEnabled =
isTestGeneratorButtonGroupSelected && isCodeTypeButtonGroupSelected && !kexForCodeLineType

if ((llmButton.isSelected && !llmSettingsState.llmSetupCheckBoxSelected && !llmSettingsState.provideTestSamplesCheckBoxSelected) ||
(evoSuiteButton.isSelected && !evoSuiteSettingsState.evosuiteSetupCheckBoxSelected)
(evoSuiteButton.isSelected && !evoSuiteSettingsState.evosuiteSetupCheckBoxSelected) ||
kexButton.isSelected
) {
nextButton.text = PluginLabelsBundle.get("ok")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ object EvoSuiteDefaultsBundle : DynamicBundle(EvoSuiteBundlePaths.defaults) {
*/
@Nls
fun get(@PropertyKey(resourceBundle = EvoSuiteBundlePaths.defaults) key: String): String = getMessage(key)
// In Intellij Platform version 2, the DynamicBundle returns the whole path and the value at the end in plugin verification.
// Each is separated by "|" (e.g., "|b|properties.llm.LLMDefaults|k|maxLLMRequest|3")
// if we do not split them here, the process will throw java.lang.NumberFormatException
.split("|").last()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.testspark.bundles.kex

object KexBundlePaths {
const val defaults: String = "properties.kex.KexDefaults"
const val messages: String = "properties.kex.KexMessages"
const val labels: String = "properties.kex.KexLabels"
const val settings: String = "properties.kex.KexSettings"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jetbrains.research.testspark.bundles.kex

import com.intellij.DynamicBundle
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.PropertyKey

/**
* Loads the `resources` directory.
*/
object KexDefaultsBundle : DynamicBundle(KexBundlePaths.defaults) {

/**
* Gets the requested default value.
*/
@Nls
fun get(@PropertyKey(resourceBundle = KexBundlePaths.defaults) key: String): String = getMessage(key)
// In Intellij Platform version 2, the DynamicBundle returns the whole path and the value at the end in plugin verification.
// Each is separated by "|" (e.g., "|b|properties.llm.LLMDefaults|k|maxLLMRequest|3")
// if we do not split them here, the process will throw java.lang.NumberFormatException
.split("|").last()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jetbrains.research.testspark.bundles.kex

import com.intellij.DynamicBundle
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.PropertyKey

/**
* Loads the `resources` directory.
*/
object KexLabelsBundle : DynamicBundle(KexBundlePaths.labels) {

/**
* Gets the requested default value.
*/
@Nls
fun get(@PropertyKey(resourceBundle = KexBundlePaths.labels) key: String): String = getMessage(key)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jetbrains.research.testspark.bundles.kex

import com.intellij.DynamicBundle
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.PropertyKey

/**
* Loads the `resources` directory.
*/
object KexMessagesBundle : DynamicBundle(KexBundlePaths.messages) {

/**
* Gets the requested default value.
*/
@Nls
fun get(@PropertyKey(resourceBundle = KexBundlePaths.messages) key: String): String = getMessage(key)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jetbrains.research.testspark.bundles.kex

import com.intellij.DynamicBundle
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.PropertyKey

/**
* Loads the `resources` directory.
*/
object KexSettingsBundle : DynamicBundle(KexBundlePaths.settings) {

/**
* Gets the requested default value.
*/
@Nls
fun get(@PropertyKey(resourceBundle = KexBundlePaths.settings) key: String): String = getMessage(key)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.jetbrains.research.testspark.data.kex

enum class KexMode {
Symbolic, Concolic,
edwin1729 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading