2025-12-23 12:08:28 +03:00

95 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Тесты для проекта BetterCallPraskovia
## Структура тестов
```
tests/
├── conftest.py
├── unit/
│ ├── test_rag_service.py
│ ├── test_user_service.py
│ ├── test_deepseek_client.py
│ ├── test_document_use_cases.py
│ └── test_collection_use_cases.py
├── integration/
│ └── test_rag_integration.py
└── metrics/
└── test_hit_at_5.py
```
## Установка зависимостей
```bash
pip install -r tests/requirements.txt
```
## Запуск тестов
### Все тесты
```bash
pytest
```
### Только юнит-тесты
```bash
pytest tests/unit/
```
### Только интеграционные тесты
```bash
pytest tests/integration/
```
### Только тесты метрик
```bash
pytest tests/metrics/
```
### Только тесты tg_bot
```bash
pytest tests/unit/test_rag_service.py tests/unit/test_user_service.py tests/unit/test_deepseek_client.py
```
### С покрытием кода
```bash
pytest --cov=backend/src --cov=tg_bot --cov-report=html
```
### С минимальным покрытием 65%
```bash
pytest --cov-fail-under=65
```
## Метрика hit@5
Проверка что в топ-5 релевантных документов есть хотя бы 1 нужный документ.
- **hit@5 = 1**, если есть хотя бы 1 релевантный документ в топ-5
- **hit@5 = 0**, если нет релевантных документов в топ-5
Среднее значение hit@5 для всех запросов должно быть **> 50%**
## Покрытие кода
**coverage ≥ 65%**
Проверка покрытия:
```bash
pytest --cov=backend/src --cov=tg_bot --cov-report=term-missing --cov-fail-under=65
```
## Маркеры тестов
- `@pytest.mark.unit` - юнит-тесты
- `@pytest.mark.integration` - интеграционные тесты
- `@pytest.mark.metrics` - тесты метрик
- `@pytest.mark.slow` - медленные тесты
Запуск по маркерам:
```bash
pytest -m unit
pytest -m integration
pytest -m metrics
```