* Mostly finish pytest to Bats conversion * Add Bats version note to testing docs * Move Bats CI check to separate job
2.1 KiB
Testing
Originally, the tests were written in pytest. However, tests are in the process of being converted to Bats so coverage can be calculated.
Bats Testing
We require a somewhat recent version of Bats. Version v1.8.1 is tested in CI. Once it is installed, the tests can be executed like so:
bats ./tests
We highly recommend adding tests for new features and fixes.
Code Coverage
Coverage can be calculated with bashcov like so:
bashcov -- bats ./tests
By default, the report will be generated in ./coverage/index.html.
Python Testing
The test part depends on:
- python >= 3.11
- poetry >= 1.8.0
- pytest >= 8.1.2
- gitpython >= 3.1.43
So the versions are higher than above is recommended.
How to run the tests
- Install
poetry - Install the dependencies via
poetry install - Run
poetry run pytest
It is done or go without poetry,
- Install python >= 3.11
- Install pytest >= 8.1.2
- Install gitpython >= 3.1.43
- Install testpath >= 0.6.0
- Run
pytest
The second way maybe blocked the some missing dependencies at someday, so the first one is recommended.
What and how to create a unit test
One command has a unit test, because one git-* command is just do one thing, so we can eat a piece of git-* command in one time.
For example,
- The
git-aliasshould have a test suite, so createtest_git_alias.pyin the directorytest - Create a test class
TestGitAliasin thetest_git_alias.py - Create a test case
test_init, and some test fixtures can be used,temp_repo,named_temp_repoetc.temp_repois module scoped fixture which create a temporary directory and available in the test suitetest_git_alias.py.named_temp_repois just same astemp_repoexcept the custom directory renaming.
- Loop the third step until the 100% coverage of the function of the
git-alias