2023-11-13 12:47:53 +00:00
|
|
|
# Project 02 - Python test generator
|
|
|
|
|
|
|
|
### About the Project
|
|
|
|
|
|
|
|
This project has the goal of writing a search based automated test generator for Python.
|
|
|
|
It is part of the Knowledge Search & Extraction - 2023 course from the Università della Svizzera italiana.
|
|
|
|
|
|
|
|
In this repository, you can find the following files:
|
2023-12-09 17:27:49 +00:00
|
|
|
|
|
|
|
- `benchmark/` folder: which contains the benchmark of functions under test to be instrumented
|
2023-11-13 12:47:53 +00:00
|
|
|
|
|
|
|
Note: Feel free to modify this file according to the project's necessities.
|
|
|
|
|
2023-11-13 13:45:51 +00:00
|
|
|
## Environment setup
|
2023-11-13 12:47:53 +00:00
|
|
|
|
2023-11-13 13:45:51 +00:00
|
|
|
To install the required dependencies make sure `python3` points to a Python 3.10 or 3.11 installation and then run:
|
|
|
|
|
|
|
|
```shell
|
2023-12-20 13:19:45 +00:00
|
|
|
python3.8 -m venv env
|
2023-11-13 13:45:51 +00:00
|
|
|
source env/bin/activate
|
|
|
|
pip install -r requirements.txt
|
|
|
|
```
|
2023-12-09 17:27:49 +00:00
|
|
|
|
|
|
|
## Instrumentation (Part 1)
|
|
|
|
|
|
|
|
To generate the instrumented code for all the files in the benchmark run the command:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
python3 ./instrument.py
|
|
|
|
```
|
|
|
|
|
|
|
|
The generated files are created in the directory `instrumented`. Each file name matches the file name of the
|
|
|
|
corresponding source file in `benchmark`.
|
|
|
|
|
|
|
|
## Test case generation (Part 2 and Part 3)
|
|
|
|
|
|
|
|
To generate test cases for all files in the benchmark run the command:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
python3 ./genetic.py
|
|
|
|
```
|
|
|
|
|
2023-12-11 14:43:53 +00:00
|
|
|
The test suite is created in the directory `tests`. One test file is generated for each file present in the
|
|
|
|
`benchmark` directory. Run the command with the `-h` options for more details on partial generation.
|
2023-12-09 17:27:49 +00:00
|
|
|
|
|
|
|
The test suite can be then executed over the benchmark code with the command:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
python3 -m unittest discover tests
|
|
|
|
```
|