Skip to content

Commit

Permalink
Added create test
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Aug 28, 2024
1 parent 516cf65 commit 251e187
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public interface ExceptionAssistant {

@UserMessage("""
I have the following java exception:
I have the following {programmingLanguage} exception:
```
{stacktrace}
```
Expand All @@ -46,7 +46,7 @@ public interface ExceptionAssistant {
public SuggestedFix suggestFix(String programmingLanguage, String product, String version, String stacktrace, String source);

@UserMessage("""
I have the following java exception:
I have the following {programmingLanguage} exception:
```
{stacktrace}
```
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/chappiebot/test/SuggestedTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.chappiebot.test;

/**
* Contains the suggested test from AI
*
* @author Phillip Kruger ([email protected])
*/
public record SuggestedTest(String explanation, String suggestedTestSource) {
}
41 changes: 41 additions & 0 deletions src/main/java/org/chappiebot/test/TestAssistant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.chappiebot.test;

import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;
import io.quarkiverse.langchain4j.RegisterAiService;

@RegisterAiService
@SystemMessage("""
You are an AI assistant helping to create Unit tests in {programmingLanguage} code from a {product} {version} application.
You will receive the code that needs a test.
Approach this task step-by-step, take your time and do not skip steps.
Respond with a json file, and only a json file, that is valid, and can be parsed in {programmingLanguage}.
You must respond in a valid JSON format.
You must not wrap JSON response in backticks, markdown, or in any other way, but return it as plain text.
The json response must contain the following fields:
- explanation
- suggestedTestSource (this must be the full source code for the test class. Note that this suggested test source should compile)
JSON Structure:
{
'explanation': 'String',
'suggestedTestSource: 'String'
}
""")
public interface TestAssistant {

@UserMessage("""
I have the following {programmingLanguage} class:
```
{source}
```
Please provide a test.
""")
public SuggestedTest suggestTest(String programmingLanguage, String product, String version, String source);

}
21 changes: 21 additions & 0 deletions src/main/java/org/chappiebot/test/TestEndpoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.chappiebot.test;

import io.quarkiverse.jsonrpc.runtime.api.JsonRPCApi;
import jakarta.inject.Inject;
/**
* The JsonRPC Endpoint for test creation
* @author Phillip Kruger ([email protected])
*/
@JsonRPCApi("testing")
public class TestEndpoint {

@Inject TestAssistant testAssistant;

public SuggestedTest suggesttest(String programmingLanguage,
String product,
String version,
String source) {

return testAssistant.suggestTest(programmingLanguage, product, version, source);
}
}

0 comments on commit 251e187

Please sign in to comment.