Skip to content

Commit

Permalink
Merge branch 'main' into coverup-thyself
Browse files Browse the repository at this point in the history
  • Loading branch information
jaltmayerpizzorno committed Apr 22, 2024
2 parents f7e5b88 + fdb7582 commit 3fd3cb5
Show file tree
Hide file tree
Showing 18 changed files with 886 additions and 404 deletions.
Binary file added CoverUp-arxiv-2403.16218.pdf
Binary file not shown.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!--
<img src="images/logo.png?raw=True" align="right" width="20%"/>

# CoverUp: Automatically Generating Higher-Coverage Test Suites with AI
# CoverUp: Automatically Generating Higher-Coverage Test Suites with AI !
-->
<img src="images/logo-with-title.png?raw=True" align="right" width="100%"/>

by [Juan Altmayer Pizzorno](https://jaltmayerpizzorno.github.io) and [Emery Berger](https://emeryberger.com)
at UMass Amherst's [PLASMA lab](https://plasma-umass.org/).
Expand All @@ -19,36 +21,41 @@ To generate tests, it first measures your suite's coverage using [SlipCover](htt
It then selects portions of the code that need more testing (that is, code that is uncovered).
CoverUp then engages in a conversation with an [LLM](https://en.wikipedia.org/wiki/Large_language_model),
prompting for tests, checking the results to verify that they run and increase coverage (again using SlipCover), and re-prompting for adjustments as necessary.
Finally, CoverUp checks that the new tests integrate well, attempting to resolve any issues it finds.
Finally, CoverUp optionally checks that the new tests integrate well, attempting to resolve any issues it finds.

## Installing CoverUp
For technical details and a complete evaluation, see our arXiv paper, [_CoverUp: Coverage-Guided LLM-Based Test Generation_](https://arxiv.org/abs/2403.16218) ([PDF](https://github.com/plasma-umass/CoverUp/blob/main/CoverUp-arxiv-2403.16218.pdf)).

## Installing CoverUp
CoverUp is available from PyPI, so you can install simply with
```shell
$ python3 -m pip install coverup
```

Currently, CoverUp requires an [OpenAI account](https://platform.openai.com/signup) to run (we plan to support local models in the near future).
Your account will also need to have a [positive balance](https://platform.openai.com/account/usage).
Create an [API key](https://platform.openai.com/api-keys) and store its "secret key" (usually a
### LLM model access
CoverUp can be used with OpenAI, Anthropic or AWS Bedrock models; it requires that the
access details be defined as shell environment variables: `OPENAI_API_KEY`,
`ANTHROPIC_API_KEY` or `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY`/`AWS_REGION_NAME`, respectively.

For example, for OpenAI you would create an [account](https://platform.openai.com/signup), ensure
it has a [positive balance](https://platform.openai.com/account/usage) and then create an
an [API key](https://platform.openai.com/api-keys), storing its "secret key" (usually a
string starting with `sk-`) in an environment variable named `OPENAI_API_KEY`:
```shell
$ export OPENAI_API_KEY=<...your-api-key...>
```

## Using CoverUp

If your module's source code is in `src` and your tests in `tests`, you can run CoverUp as
If your module is named `mymod`, its sources are under `src` and the tests under `tests`, you can run CoverUp as
```shell
$ coverup --source-dir src --tests-dir tests
$ coverup --source-dir src/mymod --tests-dir tests
```
CoverUp then creates tests named `test_coverup_N.py`, where `N` is a number, under the `tests` directory.

### Example

Here we have CoverUp create additional tests for the popular package [Flask](https://flask.palletsprojects.com/):
```
$ coverup --source-dir src/flask --tests-dir tests
$ coverup --source-dir src/flask --tests-dir tests --disable-polluting --no-isolate-tests
Measuring test suite coverage... starting coverage: 90.2%
Prompting gpt-4-1106-preview for tests to increase coverage...
100%|███████████████████████████████████████████████████| 95/95 [02:49<00:00, 1.79s/it, usage=~$3.30, G=51, F=141, U=22, R=0]
Expand Down
Binary file modified images/comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/logo-with-title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ dependencies = [
"tiktoken",
"aiolimiter",
"tqdm",
"llm_utils",
"slipcover>=1.0.3",
"slipcover>=1.0.8",
"pytest-forked",
"litellm>=1.33.1"
]

Expand Down
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CoverUp.egg-info
Loading

0 comments on commit 3fd3cb5

Please sign in to comment.