initial commit
This commit is contained in:
138
tests/README.md
Normal file
138
tests/README.md
Normal file
@@ -0,0 +1,138 @@
|
||||
# 🧪 Tests del Balotario Licencia A-I
|
||||
|
||||
Este directorio contiene tests automatizados para verificar el funcionamiento correcto de la aplicación Flask.
|
||||
|
||||
## 📁 Archivos de Test
|
||||
|
||||
### 🐍 Tests Automatizados con pytest
|
||||
|
||||
#### `test_app.py`
|
||||
- **Propósito**: Tests completos de la aplicación Flask
|
||||
- **Verifica**:
|
||||
- Páginas web (index, study, practice, exam)
|
||||
- API endpoints (/api/questions)
|
||||
- Estructura de datos de preguntas
|
||||
- Archivos estáticos (CSS, JS, favicon)
|
||||
|
||||
#### `test_parser.py`
|
||||
- **Propósito**: Tests del parser de markdown
|
||||
- **Verifica**:
|
||||
- Parsing correcto de preguntas, opciones y respuestas
|
||||
- Soporte para imágenes locales y remotas
|
||||
- Estructura de datos válida
|
||||
|
||||
#### `test_clean_parser.py`
|
||||
- **Propósito**: Tests de limpieza de emojis ✅
|
||||
- **Verifica**: Eliminación correcta de marcadores visuales
|
||||
|
||||
#### `conftest.py`
|
||||
- **Propósito**: Configuración global de pytest
|
||||
- **Contiene**: Fixtures para cliente Flask y configuración de tests
|
||||
|
||||
## 🚀 Cómo Ejecutar los Tests
|
||||
|
||||
### Opción 1: Usando Makefile (Recomendado)
|
||||
```bash
|
||||
# Ejecutar todos los tests con cobertura
|
||||
make test
|
||||
|
||||
# Instalar dependencias de desarrollo
|
||||
make install-dev
|
||||
```
|
||||
|
||||
### Opción 2: Usando pytest directamente
|
||||
```bash
|
||||
# Activar entorno virtual
|
||||
source venv/bin/activate # Linux/Mac
|
||||
# o
|
||||
venv\Scripts\activate # Windows
|
||||
|
||||
# Ejecutar todos los tests
|
||||
pytest
|
||||
|
||||
# Con cobertura detallada
|
||||
pytest --cov=. --cov-report=html --cov-report=term-missing
|
||||
|
||||
# Ejecutar tests específicos
|
||||
pytest tests/test_app.py
|
||||
pytest tests/test_parser.py
|
||||
```
|
||||
|
||||
### Ver Reporte de Cobertura
|
||||
```bash
|
||||
# Abrir reporte HTML (se genera automáticamente)
|
||||
open htmlcov/index.html # Mac
|
||||
xdg-open htmlcov/index.html # Linux
|
||||
start htmlcov/index.html # Windows
|
||||
```
|
||||
|
||||
## 📊 Cobertura de Tests
|
||||
|
||||
### ✅ Funcionalidades Probadas (15 tests)
|
||||
- [x] **Páginas web**: Index, Study, Practice, Exam
|
||||
- [x] **API endpoints**: /api/questions con diferentes modos
|
||||
- [x] **Parser de markdown**: Preguntas, opciones, respuestas correctas
|
||||
- [x] **Imágenes**: Soporte local y remoto
|
||||
- [x] **Archivos estáticos**: CSS, JS, favicon
|
||||
- [x] **Validación de datos**: Estructura de preguntas
|
||||
- [x] **Manejo de errores**: Parámetros inválidos
|
||||
- [x] **Limpieza de emojis**: Eliminación de marcadores ✅
|
||||
|
||||
### 📈 Estadísticas Actuales
|
||||
- **Tests**: 15 pasando ✅
|
||||
- **Cobertura**: ~67% del código
|
||||
- **Archivos cubiertos**: app.py (82%), config.py (100%)
|
||||
|
||||
### 🔄 Posibles Mejoras Futuras
|
||||
- [ ] Tests de JavaScript (frontend)
|
||||
- [ ] Tests de integración completa
|
||||
- [ ] Tests de rendimiento
|
||||
- [ ] Tests de accesibilidad
|
||||
- [ ] Tests de responsive design
|
||||
|
||||
## 🛠️ Desarrollo de Tests
|
||||
|
||||
### Agregar Nuevos Tests
|
||||
1. Crear archivo `test_[funcionalidad].py` en el directorio `tests/`
|
||||
2. Usar las fixtures de `conftest.py` (client, app)
|
||||
3. Seguir el patrón de naming: `test_[descripcion]()`
|
||||
4. Documentar en este README
|
||||
|
||||
### Convenciones
|
||||
- **Naming**: `test_[funcionalidad]_[caso]()`
|
||||
- **Assertions**: Usar `assert` con mensajes descriptivos
|
||||
- **Fixtures**: Reutilizar `client` y `app` de conftest.py
|
||||
- **Docstrings**: Describir qué verifica cada test
|
||||
|
||||
### Ejemplo de Test
|
||||
```python
|
||||
def test_new_feature(client):
|
||||
"""Test that new feature works correctly."""
|
||||
response = client.get('/new-endpoint')
|
||||
assert response.status_code == 200
|
||||
assert b'expected content' in response.data
|
||||
```
|
||||
|
||||
## 🐛 Debugging
|
||||
|
||||
### Si un Test Falla
|
||||
1. **Leer el mensaje de error** completo
|
||||
2. **Ejecutar test individual**: `pytest tests/test_app.py::test_specific_function -v`
|
||||
3. **Verificar fixtures**: Asegurar que `conftest.py` esté correcto
|
||||
4. **Revisar imports**: Verificar que los módulos se importen correctamente
|
||||
|
||||
### Comandos Útiles
|
||||
```bash
|
||||
# Test específico con output detallado
|
||||
pytest tests/test_app.py::test_index_page -v -s
|
||||
|
||||
# Parar en el primer fallo
|
||||
pytest -x
|
||||
|
||||
# Mostrar variables locales en fallos
|
||||
pytest --tb=long
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Nota**: Estos son tests automatizados que se ejecutan con pytest. Proporcionan verificación continua de que la aplicación funciona correctamente.
|
||||
Reference in New Issue
Block a user