Last active
January 4, 2024 07:32
-
-
Save Curt-Park/a51e47d5276b433db122ca7819fee0a7 to your computer and use it in GitHub Desktop.
unit test generation with pynguin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pynguin is now able to generate assertions for simple data types (int, float, str, and bool), | |
# as well as checks for None return values. | |
# https://pynguin.readthedocs.io/en/latest/index.html | |
def fibonacci(n: int) -> int: | |
assert n >= 0 | |
a, b = 1, 0 | |
for _ in range(n): | |
a, b = a + b, a | |
return a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: `$ make utest MODULE_NAME=fibonacci` | |
utest: | |
if [ ! -d "test" ]; then mkdir test; fi | |
pynguin --algorithm RANDOM --project_path . --output_path test --module_name ${MODULE_NAME} | |
# usage: `$ make run-utest` | |
run-utest: | |
env PYTHONPATH=. pytest test --verbose --cov . --cov-report=html --cov-report=term-missing | |
# usage: `$ make show-cov MODULE_NAME=fibonacci` | |
show-cov: | |
open -a "Google Chrome" htmlcov/${MODULE_NAME}_py.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install -r requirements.txt | |
pynguin == 0.8.0 | |
pytest == 6.2.3 | |
pytest-cov == 2.11.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment