Skip to content

Commit c8ad3c7

Browse files
committed
feat: add support for strict mutation testing without the use of LLM
1 parent 5243154 commit c8ad3c7

File tree

25 files changed

+1407
-905
lines changed

25 files changed

+1407
-905
lines changed

README.md

Lines changed: 18 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
</a>
1515
</div>
1616

17-
<div align="center">
18-
<video src="https://github.com/codeintegrity-ai/mutahunter/assets/37044660/cca8a41b-b97e-4ce1-806d-e53d475d4226"></video>
19-
<p>Demo video of running mutation testing on a Go web project</p>
20-
</div>
21-
2217
## Table of Contents
2318

2419
- [Overview](#overview)
@@ -37,21 +32,23 @@ Mutahunter uses LLM models to inject context-aware faults into your codebase. Th
3732

3833
## Features
3934

40-
- **Change-Based:** Runs mutation tests on modified files and lines based on the latest commit or pull request changes.
41-
- **Multi-Language Support:** Compatible with languages that provide coverage reports in Cobertura XML, Jacoco XML, and lcov formats.
42-
- **Extensible:** Extensible to additional languages and testing frameworks.
43-
- **Context-Aware:** Uses a map of your entire git repository to generate contextually relevant mutants using [aider](https://aider.chat/docs/repomap.html).
44-
- **LLM Support:** Supports self-hosted, Anthropic, OpenAI, and any LLM models using [LiteLLM](https://github.com/BerriAI/litellm).
45-
- **Mutant Report** Provides detailed reports on mutation coverage, killed mutants, and survived mutants.
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/pilot/aider/queries/) to see the supported operators. We welcome contributions to add more operators and languages.
36+
- **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+
- **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+
- **Detailed Mutant Reports:** Provides comprehensive reports on mutation coverage, killed mutants, and survived mutants.
4640

47-
## Getting Started
41+
## Recommended Mutation Testing Process
42+
43+
![Workflow](/images/diagram.svg)
4844

49-
⚠️ We highly suggest:
45+
1. **Achieve High Line Coverage:** Ensure your test suite has high line coverage, preferably 100%.
5046

51-
- Using `--modified-files-only` flag to run mutation testing on only on modified files.
52-
- Using `--only-mutate-file-paths` flag to focus on specific files. T
47+
2. **Strict Mutation Testing:** Use strict mutation testing to improve mutation coverage without additional cost. Utilize the `--only-mutate-file-paths` flag for targeted testing on critical files.
5348

54-
The above flags will make the mutation testing significantly **faster** and **cost effective.**
49+
3. **LLM-Based Mutation Testing on Changed Files:** Inject context-aware mutants using LLMs on changed files during pull requests as the final line of defense. Use the `--modified-files-only` flag to focus on recent changes. In this way it will make the mutation testing significantly **faster** and **cost effective.**
50+
51+
## Getting Started
5552

5653
```bash
5754
# Install Mutahunter package via GitHub. Python 3.11+ is required.
@@ -91,61 +88,15 @@ $ mutahunter run --test-command "pytest tests/unit" --code-coverage-report-path
9188
9289
Go to the examples directory to see how to run Mutahunter on different programming languages:
9390
94-
- [Go Example](/examples/go_webservice/)
91+
Check [Java Example](/examples/java_maven/) to see some interesting LLM-based mutation testing examples.
92+
9593
- [Java Example](/examples/java_maven/)
94+
- [Go Example](/examples/go_webservice/)
9695
- [JavaScript Example](/examples/js_vanilla/)
9796
- [Python FastAPI Example](/examples/python_fastapi/)
9897
9998
Feel free to add more examples! ✨
10099
101-
### Command Options
102-
103-
The mutahunter run command has the following options:
104-
105-
```plaintext
106-
Options:
107-
--model <MODEL>
108-
Description: LLM model to use for mutation testing. We use LiteLLM to call the model.
109-
Default: `gpt-4o`
110-
Required: Yes
111-
Example: `--model gpt-4o`
112-
113-
--api-base <URL>
114-
Description: Base URL for the API endpoint.
115-
Default: `https://api.openai.com`
116-
Required: No
117-
Example: `--api-base https://api.openai.com`
118-
119-
--test-command <COMMAND>
120-
Description: The command used to execute the tests. Specify a single test file to run the tests on.
121-
Required: Yes
122-
Example: `--test-command pytest test_app.py`
123-
124-
--code-coverage-report-path <PATH>
125-
Description: Path to the code coverage report of the test suite.
126-
Required: Yes
127-
Example: `--code-coverage-report-path /path/to/coverage.xml`
128-
129-
--coverage-type <TYPE>
130-
Description: Type of coverage report. Currently supports `cobertura`, `jacoco`, `lcov`.
131-
Required: Yes
132-
Example: `--coverage-type cobertura`
133-
134-
--exclude-files <FILES>
135-
Description: Files to exclude from analysis.
136-
Required: No
137-
Example: `--exclude-files file1.py file2.py`
138-
139-
--only-mutate-file-paths <FILES>
140-
Description: Specifies which files to mutate. This is useful when you want to focus on specific files and it makes the mutations faster!
141-
Required: No
142-
Example: `--only-mutate-file-paths file1.py file2.py`
143-
144-
--modified-files-only
145-
Description: Runs mutation testing only on modified files and lines based on the latest commit.
146-
Required: No
147-
```
148-
149100
## Mutant Report
150101
151102
Check the logs directory to view the report:
@@ -160,21 +111,15 @@ Help us improve Mutahunter and get rewarded! We have a cash bounty program to in
160111
161112
## Roadmap
162113
163-
### Mutation Testing Capabilities
164-
165114
- [x] **Fault Injection:** Utilize advanced LLM models to inject context-aware faults into the codebase, ensuring comprehensive mutation testing.
166115
- [x] **Language Support:** Expand support to include various programming languages.
167116
- [x] **Support for Other Coverage Report Formats:** Add compatibility for various coverage report formats.
117+
- [x] **Change-Based Testing:** Implement mutation testing on modified files based on the latest commit or pull request changes.
118+
- [x] **Extreme Mutation Testing:** Apply mutations to the codebase without using LLMs to detect pseudo-tested methods with significantly lower computational cost.
168119
- [ ] **Mutant Analysis:** Automatically analyze survived mutants to identify potential weaknesses in the test suite. Any suggestions are welcome!
169-
170-
### Continuous Integration and Deployment
171-
172120
- [ ] **CI/CD Integration:** Develop connectors for popular CI/CD platforms like GitHub Actions.
173-
- [ ] **PR Changeset Focus:** Generate mutations specifically targeting pull request changesets or modified code based on commit history.
174121
- [ ] **Automatic PR Bot:** Create a bot that automatically identifies bugs from the survived mutants list and provides fix suggestions.
175122
176-
---
177-
178123
## Acknowledgements
179124
180125
Mutahunter makes use of the following open-source libraries:

examples/go_webservice/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,22 @@ gocov convert coverage.out | gocov-xml > coverage.xml
1616

1717
## Running Mutahunter to analyze the tests
1818

19+
Currently test coverage is 96.6%. Let's see what the mutation coverage is.
20+
1921
```bash
22+
# --extreme flag is used to run the mutation testing in extreme mode. This does not use the LLM-based model.
23+
mutahunter run --test-command "go test" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.go" --extreme
24+
25+
# After achieving a high mutation score, let's say 90%, you can check one last time using LLM-based
26+
27+
# go seems to do pretty bad when using gpt-3.5-turbo, so we recommend using gpt-4o
28+
2029
export OPENAI_API_KEY=your-key-goes-here
21-
mutahunter run --test-command "go test" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.go"
30+
31+
mutahunter run --test-command "go test" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.go" --model "gpt-4o"
32+
33+
## you can use --modifies-files-only to only mutate the files that are modified by the test suite
34+
mutahunter run --test-command "go test" --code-coverage-report-path "coverage.xml" --only-mutate-file-paths "app.go" --extreme --modifies-files-only
35+
36+
## and then keeping improving the test suite until you get 100%
2237
```

0 commit comments

Comments
 (0)