Weblate 測試套件與連續集成
測試套件存在於多數當前代碼,通過為任何新的功能添加測試情況來擴大覆蓋範圍,並確認其正常工作。
連續集成
Current test results can be found on GitHub Actions and coverage is reported on Codecov.
有幾項工作來確認不同的方面:
單元測試
文件構建與外部鏈接
來自所有支持的發佈版本的合併測試
代碼整理
設置確認(確保生成的 dist 文件不丟失任何內容,並可以測試)
CI 的配置在 .github/workflows
目錄中。它重度使用了 ci
目錄中的幫助腳本。腳本還可以手動執行,但它們需要一些環境變量,多數用來定義 Django 設置要使用的文件和資料庫連接。它的示例定義在 scripts/test-database
中:
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Simple way to configure test database from environment
# shellcheck shell=sh
# Database backend to use postgresql / mysql / mariadb
export CI_DATABASE="${1:-postgresql}"
# Database server configuration
export CI_DB_USER=weblate
export CI_DB_PASSWORD=weblate
export CI_DB_HOST=127.0.0.1
# Django settings module to use
export DJANGO_SETTINGS_MODULE=weblate.settings_test
簡單的執行看起來可以像這樣:
. scripts/test-database.sh
./ci/run-migrate
./ci/run-test
./ci/run-docs
本地測試
如果本地運行測試套件,要使用:
DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py test
提示
您會需要使用資料庫(PostgreSQL)服務器來檢測。 Django 預設新建另外的資料庫,以 test_
前綴來運行測試,因此在您的設置配置使用 weblate
的情況下,測試會使用 test_weblate
資料庫。設置的指示請參見 Weblate 的資料庫設置。
weblate/settings_test.py
也用在 CI 環境中(請參見 連續集成),並且可以使用環境變量調整:
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Simple way to configure test database from environment
# shellcheck shell=sh
# Database backend to use postgresql / mysql / mariadb
export CI_DATABASE="${1:-postgresql}"
# Database server configuration
export CI_DB_USER=weblate
export CI_DB_PASSWORD=weblate
export CI_DB_HOST=127.0.0.1
# Django settings module to use
export DJANGO_SETTINGS_MODULE=weblate.settings_test
運行測試前,應該收集靜態文件,因為一些測試在出現時依賴於它們:
DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py collectstatic
您也可以指定要運行的各自測試:
DJANGO_SETTINGS_MODULE=weblate.settings_test ./manage.py test weblate.gitexport
提示
測試也可以在開發者 docker 容器內執行,請參見 在 Docker 中本地運行 Weblate。
也參考
運行並為 Django寫測試的更多信息請參見 Testing in Django。