跳转至

测试规范

开发中

此文档正在编写中,内容将持续更新。

本文档规定了Genesis项目的测试标准和最佳实践。

🎯 测试原则

1. 测试金字塔

  • 单元测试 (70%): 测试单个函数和类
  • 集成测试 (20%): 测试组件间交互
  • 端到端测试 (10%): 测试完整工作流

2. 测试覆盖率

  • 目标覆盖率: 90%+
  • 关键模块要求: 95%+
  • 新代码要求: 100%

📋 测试分类

单元测试

Python
def test_tensor_creation():
    """Test basic tensor creation."""
    x = genesis.randn(3, 4)
    assert x.shape == (3, 4)
    assert x.dtype == genesis.float32

性能测试

Python
@pytest.mark.benchmark
def test_matmul_performance():
    """Benchmark matrix multiplication performance."""
    # WIP: 性能测试实现
    pass

GPU测试

Python
@pytest.mark.cuda
def test_cuda_operations():
    """Test CUDA-specific operations."""
    if not genesis.cuda.is_available():
        pytest.skip("CUDA not available")

    x = genesis.randn(10, 10, device='cuda')
    y = genesis.matmul(x, x)
    assert y.device.type == 'cuda'

🚀 运行测试

Bash
# 所有测试
pytest tests/ -v

# 特定标记
pytest tests/ -m "not slow" -v

# 覆盖率报告
pytest tests/ --cov=genesis --cov-report=html

📊 测试工具

  • pytest: 主要测试框架
  • pytest-cov: 覆盖率统计
  • pytest-benchmark: 性能测试
  • pytest-xdist: 并行测试

📘 文档状态: 正在编写中,预计在v0.2.0版本完成。