pip install -r requirements-dev.txtpytestpytest --cov=jsonic --cov-report=html --cov-report=term-missingopen htmlcov/index.html # macOS
# or
xdg-open htmlcov/index.html # Linux
# or
start htmlcov/index.html # Windows# Unit tests only
pytest -m unit
# Edge case tests only
pytest -m edge_case
# Integration tests only
pytest -m integration# Serialization tests
pytest tests/unit/test_serialization.py
# Deserialization tests
pytest tests/unit/test_deserialization.py
# Edge cases
pytest tests/edge_cases/test_edge_cases.py
# Custom serializers
pytest tests/unit/test_custom_serializers.py
# Register type tests
pytest tests/unit/test_register_type.py# Specific class
pytest tests/unit/test_serialization.py::TestPrimitiveTypes
# Specific test
pytest tests/unit/test_serialization.py::TestPrimitiveTypes::test_primitive_serialization
# Pattern matching
pytest -k "serialization" # Run all tests with "serialization" in name
pytest -k "edge_case" # Run all edge case tests# Show test names as they run
pytest -v
# Show print statements
pytest -s
# Both
pytest -vspytest -xpytest --lfpytest --ffpytest --cov=jsonicpytest --cov=jsonic --cov-report=term-missingpytest --cov=jsonic --cov-report=htmlpytest --cov=jsonic --cov-branch --cov-report=term-missingpytest --cov=jsonic --cov-fail-under=90tests/
├── conftest.py # Shared fixtures
├── unit/ # Unit tests
│ ├── test_serialization.py # serialize() tests
│ ├── test_deserialization.py # deserialize() tests
│ ├── test_register_type.py # register_jsonic_type() tests
│ └── test_custom_serializers.py # Custom serializer/deserializer tests
└── edge_cases/ # Edge case tests
└── test_edge_cases.py # Comprehensive edge cases
- Primitive types (int, float, str, bool, None)
- Collections (list, dict, nested structures)
- Serializable classes
- Custom serializers/deserializers
- register_jsonic_type()
- Private attributes (serialize_private_attributes flag)
- Transient attributes
- Init parameter mapping
- Expected type validation
- String input/output formats
- Datetime serialization
- None values in all contexts
- Empty collections
- Unicode and special characters
- Deep nesting (100+ levels)
- Large collections (10k+ items)
- Special numbers (infinity, NaN)
- Mixed types
- Inheritance
- Properties
- Unserializable types
- Invalid JSON
- Type mismatches
- Missing fields
- Wrong expected_type
After running the full test suite with coverage:
pytest --cov=jsonic --cov-report=term-missingYou should see:
- 100+ tests passing
- >90% line coverage
- >85% branch coverage
- <5 seconds runtime
pip install -r requirements-dev.txtMake sure you're in the project root:
cd /path/to/Jsonic
pytestInstall pytest-cov:
pip install pytest-covCheck Python version compatibility:
python --version # Should be 3.6+- Unit tests →
tests/unit/ - Edge cases →
tests/edge_cases/ - Integration tests →
tests/integration/
def test_my_feature(simple_user_class):
user = simple_user_class("Alice", 30)
# ... test code@pytest.mark.parametrize("value,expected", [
(1, 1),
("test", "test"),
(None, None),
])
def test_roundtrip(value, expected):
assert deserialize(serialize(value)) == expected@pytest.mark.unit
def test_something():
pass
@pytest.mark.edge_case
def test_edge_case():
passdef test_error_case():
with pytest.raises(TypeError, match="Could not find serializer"):
serialize(UnserializableObject())name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, 3.10, 3.11]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run tests with coverage
run: |
pytest --cov=jsonic --cov-report=xml --cov-fail-under=90
- name: Upload coverage
uses: codecov/codecov-action@v2- Run the tests:
pytest --cov=jsonic --cov-report=html - Check coverage: Open
htmlcov/index.html - Fix any failures: Address failing tests
- Add missing tests: Cover any gaps found in coverage report
- Set up CI/CD: Add GitHub Actions workflow
- Add badge: Add coverage badge to README
- Check
TEST_COVERAGE_PLAN.mdfor detailed test strategy - Check
TEST_IMPLEMENTATION_SUMMARY.mdfor what was implemented - Run
pytest --helpfor all pytest options