Skip to content

Commit

Permalink
Merge pull request #89 from JetBrains-Research/fix-bugs
Browse files Browse the repository at this point in the history
Fix bugs and Improve test generation UI
  • Loading branch information
pderakhshanfar authored Nov 16, 2023
2 parents 26c62ad + ad142fc commit ca6545d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 47 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pluginUntilBuild = 233.*

# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
platformType = IC
platformVersion = LATEST-EAP-SNAPSHOT
platformVersion = 2023.2

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import java.awt.CardLayout
import java.awt.Dimension
import java.awt.Font
import java.awt.Toolkit
import java.awt.event.WindowEvent
import java.awt.event.WindowFocusListener
import javax.swing.BoxLayout
import javax.swing.ButtonGroup
import javax.swing.JButton
Expand Down Expand Up @@ -149,6 +151,14 @@ class TestSparkAction : AnAction() {
* @param panel the JPanel to add listeners to
*/
private fun addListeners(panel: JPanel) {
this.addWindowFocusListener(object : WindowFocusListener {
override fun windowGainedFocus(e: WindowEvent) {
}
override fun windowLostFocus(e: WindowEvent) {
dispose()
}
})

llmButton.addActionListener {
updateNextButton()
}
Expand Down
38 changes: 0 additions & 38 deletions src/main/kotlin/org/jetbrains/research/testspark/tools/Manager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,6 @@ class Manager {
companion object {
val tools: List<Tool> = listOf(EvoSuite(), Llm())

/**
* Generates tests for a given class based on the provided
* AnActionEvent.
*
* @param e the AnActionEvent used to trigger the test generation
*/
fun generateTestsForClass(e: AnActionEvent) {
if (e.project!!.service<RunnerService>().isGeneratorRunning()) return

for (tool: Tool in tools) tool.generateTestsForClass(e)
display(e, tools.size)
}

/**
* Generates tests for a given method.
*
* @param e The AnActionEvent containing information about the action event.
* @throws NullPointerException if e.project is null or if the RunnerService is not available.
*/
fun generateTestsForMethod(e: AnActionEvent) {
if (e.project!!.service<RunnerService>().isGeneratorRunning()) return

for (tool: Tool in tools) tool.generateTestsForMethod(e)
display(e, tools.size)
}

/**
* Generates tests for a specific line of code.
*
* @param e The AnActionEvent object representing the action event.
*/
fun generateTestsForLine(e: AnActionEvent) {
if (e.project!!.service<RunnerService>().isGeneratorRunning()) return

for (tool: Tool in tools) tool.generateTestsForLine(e)
display(e, tools.size)
}

/**
* Generates tests for a class using EvoSuite.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class PromptManager(
private val llmErrorManager: LLMErrorManager = LLMErrorManager()

fun generatePrompt(codeType: FragmentToTestData): String {

var prompt: String
while (true) {
prompt = when (codeType.type!!) {
Expand Down Expand Up @@ -128,7 +127,7 @@ class PromptManager(
methodPrompt = insertMethodsSignatures(methodPrompt, getInterestingPsiClasses(psiMethod))
methodPrompt = insertPolymorphismRelations(
methodPrompt,
getPolymorphismRelations(project, getInterestingPsiClasses(classesToTest), cut)
getPolymorphismRelations(project, getInterestingPsiClasses(classesToTest), cut),
)

return methodPrompt
Expand Down Expand Up @@ -159,7 +158,7 @@ class PromptManager(
linePrompt = insertMethodsSignatures(linePrompt, getInterestingPsiClasses(psiMethod))
linePrompt = insertPolymorphismRelations(
linePrompt,
getPolymorphismRelations(project, getInterestingPsiClasses(classesToTest), cut)
getPolymorphismRelations(project, getInterestingPsiClasses(classesToTest), cut),
)

return linePrompt
Expand Down Expand Up @@ -254,7 +253,7 @@ class PromptManager(

private fun insertPolymorphismRelations(
classPrompt: String,
polymorphismRelations: MutableMap<PsiClass, MutableList<PsiClass>>
polymorphismRelations: MutableMap<PsiClass, MutableList<PsiClass>>,
): String {
val keyword = "\$${PROMPT_KEYWORD.POLYMORPHISM.text}"
if (isPromptValid(PROMPT_KEYWORD.METHODS, classPrompt)) {
Expand Down Expand Up @@ -341,7 +340,7 @@ class PromptManager(
private fun getPolymorphismRelations(
project: Project,
interestingPsiClasses: MutableSet<PsiClass>,
cutPsiClass: PsiClass
cutPsiClass: PsiClass,
): MutableMap<PsiClass, MutableList<PsiClass>> {
val polymorphismRelations: MutableMap<PsiClass, MutableList<PsiClass>> = mutableMapOf()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,20 @@ class DescriptionTab(private val project: Project) {
}
}

// testSpark description setup
testSparkDescription.isOpaque = false
testSparkDescription.text = getCommonDescriptionText(getContent().preferredSize.width)

// testSpark LLM description setup
testSparkLLMDescription.isOpaque = false
testSparkLLMDescription.text = getLLMDescriptionText(getContent().preferredSize.width)

// testSpark EvoSuite description setup
testSparkEvoSuiteDescription.isOpaque = false
testSparkEvoSuiteDescription.text = getEvoSuiteDescriptionText(getContent().preferredSize.width)

// testSpark disclaimer description setup
testSparkDisclaimerDescription.isOpaque = false
testSparkDisclaimerDescription.text = getDisclaimerText(getContent().preferredSize.width)
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/defaults/TestSpark.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ llmPlatform=OpenAI
maxLLMRequest=3
maxInputParamsDepth=2
maxPolyDepth=2
classPrompt=Generate unit tests in $LANGUAGE for $NAME to achieve 100% line coverage for this class.\nDont use @Before and @After test methods.\nMake tests as atomic as possible.\nAll tests should be for $TESTING_PLATFORM.\nIn case of mocking, use $MOCKING_FRAMEWORK. But, do not use mocking for all tests.\nName all methods according to the template - [MethodUnderTest][Scenario]Test.\nThe source code of class under test is as follows:\n$CODE\nHere are the method signatures of classes used by the class under test. Only use these signatures for creating objects, not your own ideas.\n$METHODS\nPolymorphism relations:\n$POLYMORPHISM
methodPrompt=Generate unit tests in $LANGUAGE for $NAME to achieve 100% line coverage for this method.\nDont use @Before and @After test methods.\nMake tests as atomic as possible.\nAll tests should be for $TESTING_PLATFORM.\nIn case of mocking, use $MOCKING_FRAMEWORK. But, do not use mocking for all tests.\nName all methods according to the template - [MethodUnderTest][Scenario]Test.\nThe source code of method under test is as follows:\n$CODE\nHere are the method signatures of classes used by the method under test. Only use these signatures for creating objects, not your own ideas.\n$METHODS\nPolymorphism relations:\n$POLYMORPHISM
linePrompt=Generate unit tests in $LANGUAGE for line $NAME in the following code:\n$CODE\nDont use @Before and @After test methods.\nMake tests as atomic as possible.\nAll tests should be for $TESTING_PLATFORM.\nIn case of mocking, use $MOCKING_FRAMEWORK. But, do not use mocking for all tests.\nName all methods according to the template - [MethodUnderTest][Scenario]Test.\nHere are the method signatures of classes used by the method under test. Only use these signatures for creating objects, not your own ideas.\n$METHODS\nPolymorphism relations:\n$POLYMORPHISM
classPrompt=Generate unit tests in $LANGUAGE for $NAME to achieve 100% line coverage for this class.\nDont use @Before and @After test methods.\nMake tests as atomic as possible.\nAll tests should be for $TESTING_PLATFORM.\nIn case of mocking, use $MOCKING_FRAMEWORK. But, do not use mocking for all tests.\nName all methods according to the template - [MethodUnderTest][Scenario]Test, and use only English letters.\nThe source code of class under test is as follows:\n$CODE\nHere are the method signatures of classes used by the class under test. Only use these signatures for creating objects, not your own ideas.\n$METHODS\nPolymorphism relations:\n$POLYMORPHISM
methodPrompt=Generate unit tests in $LANGUAGE for $NAME to achieve 100% line coverage for this method.\nDont use @Before and @After test methods.\nMake tests as atomic as possible.\nAll tests should be for $TESTING_PLATFORM.\nIn case of mocking, use $MOCKING_FRAMEWORK. But, do not use mocking for all tests.\nName all methods according to the template - [MethodUnderTest][Scenario]Test, and use only English letters.\nThe source code of method under test is as follows:\n$CODE\nHere are the method signatures of classes used by the method under test. Only use these signatures for creating objects, not your own ideas.\n$METHODS\nPolymorphism relations:\n$POLYMORPHISM
linePrompt=Generate unit tests in $LANGUAGE for line $NAME in the following code:\n$CODE\nDont use @Before and @After test methods.\nMake tests as atomic as possible.\nAll tests should be for $TESTING_PLATFORM.\nIn case of mocking, use $MOCKING_FRAMEWORK. But, do not use mocking for all tests.\nName all methods according to the template - [MethodUnderTest][Scenario]Test, and use only English letters.\nHere are the method signatures of classes used by the method under test. Only use these signatures for creating objects, not your own ideas.\n$METHODS\nPolymorphism relations:\n$POLYMORPHISM

0 comments on commit ca6545d

Please sign in to comment.