You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -32,11 +34,12 @@ Mutahunter uses LLM models to inject context-aware faults into your codebase. Th
32
34
33
35
## Features
34
36
35
-
-**Extreme Mutation Testing:** Leverages language agnostic [TreeSitter](https://tree-sitter.github.io/) parser to apply extreme mutations to the codebase without using LLMs. [Research](https://arxiv.org/abs/2103.08480) shows that this approach is effective at detecting pseudo-tested methods with significantly lower computational cost. Currently supports Python, Java, JavaScript, and Go. Check the [scheme files](/src/mutahunter/core/queries/) to see the supported operators. We welcome contributions to add more operators and languages.
37
+
-**Automatuic Test Generation:** Generates unit tests to increase line and mutation coverage, leveraging LLMs to identify and fill gaps in test coverage. See the [Unit Test Generator](#unit-test-generator-enhancing-line-and-mutation-coverage-wip) section for more details.
38
+
-**Language Agnostic:** Compatible with languages that provide coverage reports in Cobertura XML, Jacoco XML, and lcov formats. Extensible to additional languages and testing frameworks.
36
39
-**LLM Context-aware Mutations:** Utilizes LLM models to generate context-aware mutants. [Research](https://arxiv.org/abs/2406.09843) indicates that LLM-generated mutants have higher fault detection potential, fewer equivalent mutants, and higher coupling and semantic similarity to real faults. It uses a map of your entire git repository to generate contextually relevant mutants using [aider's repomap](https://aider.chat/docs/repomap.html). Supports self-hosted LLMs, Anthropic, OpenAI, and any LLM models via [LiteLLM](https://github.com/BerriAI/litellm).
37
40
-**Change-Based Testing:** Runs mutation tests on modified files and lines based on the latest commit or pull request changes, ensuring that only relevant parts of the code are tested.
38
-
-**Language Agnostic:** Compatible with languages that provide coverage reports in Cobertura XML, Jacoco XML, and lcov formats. Extensible to additional languages and testing frameworks.
39
41
-**LLM Surviving Mutants Analysis:** Automatically analyzes survived mutants to identify potential weaknesses in the test suite, vulnerabilities, and areas for improvement.
42
+
-**Extreme Mutation Testing:** Leverages language agnostic [TreeSitter](https://tree-sitter.github.io/) parser to apply extreme mutations to the codebase without using LLMs. [Research](https://arxiv.org/abs/2103.08480) shows that this approach is effective at detecting pseudo-tested methods with significantly lower computational cost. Currently supports Python, Java, JavaScript, and Go. Check the [scheme files](/src/mutahunter/core/queries/) to see the supported operators. We welcome contributions to add more operators and languages.
40
43
41
44
## Recommended Mutation Testing Process
42
45
@@ -99,6 +102,20 @@ Check [Java Example](/examples/java_maven/) to see some interesting LLM-based mu
99
102
100
103
Feel free to add more examples! ✨
101
104
105
+
## Unit Test Generator: Enhancing Line and Mutation Coverage (WIP)
106
+
107
+
This tool generates unit tests to increase both line and mutation coverage, inspired by papers:
108
+
109
+
- [Automated Unit Test Improvement using Large Language Models at Meta](https://arxiv.org/abs/2402.09171):
110
+
- Uses LLMs to identify and fill gaps in test coverage.
111
+
- [Effective Test Generation Using Pre-trained Large Language Models and Mutation Testing](https://arxiv.org/abs/2308.16557):
112
+
- Generates tests that detect and kill code mutants, ensuring robustness.
Copy file name to clipboardExpand all lines: src/mutahunter/core/prompts/user.py
+139Lines changed: 139 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -80,3 +80,142 @@ class Mutants(BaseModel):
80
80
81
81
To reduce cognitive load, focus on quality over quantity to ensure that the mutants analysis are meaningful and provide valuable insights into the code quality and test coverage. Output your analysis in a clear and concise manner, highlighting the key points for each aspect with less than 300 words.
82
82
"""
83
+
84
+
85
+
TEST_GEN_USER_PROMPT="""
86
+
## Overview
87
+
You are a code assistant that accepts a {{ language }} source file and test file. Your goal is to generate additional unit tests to complement the existing test suite and increase line coverage against the source file.
88
+
89
+
## Guidelines:
90
+
- Analyze the provided code to understand its purpose, inputs, outputs, and key logic.
91
+
- Brainstorm test cases to fully validate the code and achieve 100% line coverage.
92
+
- Ensure the tests cover all scenarios, including exceptions or errors.
93
+
- If the original test file has a test suite, integrate new tests consistently in terms of style, naming, and structure.
94
+
- Ensure unit tests are independent and do not rely on the system's state or other tests.
95
+
- Include clear assertions in each test to validate expected behavior.
96
+
- Mock or stub external dependencies to keep tests isolated and repeatable.
97
+
98
+
## Source File
99
+
Here is the source file for which you will write tests, called `{{ source_file_name }}`. Note that line numbers have been manually added for reference. Do not include these line numbers in your response.
100
+
```{{ language }}
101
+
{{ source_file_numbered }}
102
+
```
103
+
104
+
## Test File
105
+
Here is the file that contains the existing tests, called `{{ test_file_name }}.
106
+
```{{ language }}
107
+
{{ test_file }}
108
+
```
109
+
110
+
## Line Coverage
111
+
The following line numbers are not covered by the existing tests. Your goal is to write tests that cover as many of these lines as possible.
112
+
{{ lines_to_cover }}
113
+
114
+
## Response
115
+
The output must be a JSON object wrapped in json. Do not generate more than 5 tests in a single response.
116
+
```json
117
+
{
118
+
"language": {{ language }},
119
+
"insertion_point_marker": {
120
+
"class_name": "The name of the class after which the test should be inserted.",
121
+
"method_name": "The last method name after which the test should be inserted in the class."
122
+
},
123
+
"new_tests": [
124
+
{
125
+
"test_behavior": "Short description of the behavior the test covers.",
126
+
"lines_to_cover": "List of line numbers, currently uncovered, that this specific new test aims to cover.",
127
+
"test_name": "A short unique test name reflecting the test objective.",
128
+
"test_code": "A single test function testing the behavior described in 'test_behavior'. Write it as part of the existing test suite, using existing helper functions, setup, or teardown code.",
129
+
"new_imports_code": "New imports required for the new test function, or an empty string if none. Use 'import ...' lines if relevant.",
130
+
"test_tags": ["happy path", "edge case", "other"]
131
+
}
132
+
]
133
+
}
134
+
```
135
+
{{ failed_tests_section }}
136
+
"""
137
+
138
+
MUTATION_TEST_PROMPT="""
139
+
## Overview
140
+
You are a code assistant that accepts a {{ language }} source file and test file. The current code has a line coverage of {{ line_coverage }}% and a mutation coverage of {{ mutation_coverage }}%.
141
+
142
+
Your goal is to generate additional unit tests to kill the survived mutants in the source code. To kill a mutant, you need to write a test that triggers the fault introduced by the mutant but passes for the original code.
143
+
144
+
## Source File
145
+
Here is the source file you will be writing tests against, called `{{ source_file_name }}`.
146
+
```{{ language }}
147
+
{{ source_code }}
148
+
```
149
+
## Test File
150
+
Here is the file that contains the existing tests, called `{{ test_file_name }}`
151
+
```{{ language }}
152
+
{{ test_file }}
153
+
```
154
+
155
+
## Survived Mutants
156
+
Below is a list of survived mutants. Your goal is to write tests that will detect faults based on these mutants.
157
+
```json
158
+
{{ survived_mutants }}
159
+
```
160
+
161
+
## Response
162
+
The output must be a JSON object wrapped in json. Do not generate more than 5 tests in a single response.
163
+
``json
164
+
{
165
+
"language": {{ language }},
166
+
"insertion_point_marker": {
167
+
"class_name": "The name of the class after which the test should be inserted.",
168
+
"method_name": "The last method name after which the test should be inserted in the class."
169
+
},
170
+
"new_tests": [
171
+
{
172
+
"test_behavior": "Short description of the behavior the test covers.",
173
+
"mutant_id": "The ID of the mutant this test aims to kill.",
174
+
"test_name": "A short unique test name reflecting the test objective.",
175
+
"test_code": "A single test function that tests the behavior described in 'test_behavior'. Write it as part of the existing test suite, using existing helper functions, setup, or teardown code.",
176
+
"new_imports_code": "New imports required for the new test function, or an empty string if none. Use 'import ...' lines if relevant.",
177
+
"test_tags": ["happy path", "edge case", "other"]
178
+
}
179
+
]
180
+
}
181
+
```
182
+
{{ weak_tests_section }}
183
+
184
+
{{ failed_tests_section }}
185
+
"""
186
+
187
+
MUTATION_WEAK_TESTS_TEXT="""
188
+
## Previous Iterations Passes But Fails to Kill Mutants
189
+
Below is a list of tests that pass but fail to kill the mutants. Do not generate the same tests again, and take these tests into account when generating new tests.
190
+
```json
191
+
{{ weak_tests }}
192
+
```
193
+
"""
194
+
195
+
FAILED_TESTS_TEXT="""
196
+
## Previous Iterations Failed Tests
197
+
Below is a list of failed tests that you generated in previous iterations. Do not generate the same tests again, and take the failed tests into account when generating new tests.
198
+
```json
199
+
{{ failed_test }}
200
+
```
201
+
"""
202
+
203
+
REPORT_PROMPT="""
204
+
## Overview
205
+
You are a code assistant that accepts a {{ language }} source file and test file. Your goal is to analyze the existing test suite and generate a report that provides insights into the quality and effectiveness of the tests based on the surviving mutants and failed tests.
206
+
207
+
Here is the source file that you will be writing tests against, called `{{ source_file_name }}`.
208
+
```{{ language }}
209
+
{{ source_code }}
210
+
```
211
+
## Test File
212
+
Here is the file that contains the existing tests, called `{{ test_file }}`
213
+
```{{ language }}
214
+
{{ test_code }}
215
+
```
216
+
217
+
## Survived Mutants
218
+
{{survived_mutants_section}}
219
+
220
+
Based on the surviving mutants that could not be killed by the existing tests, there might be bugs in the source code or weaknesses in the test file. Please identify potential bugs in the source code or weaknesses in the test file. The report must be in markdown format and no more than 400 words. Use concise bullet points to summarize the key insights and recommendations.
0 commit comments