xege icon indicating copy to clipboard operation
xege copied to clipboard

Add test categorization system and improve coverage from 3% to 20%

Open Copilot opened this issue 3 months ago • 5 comments

Task: Optimize Unit Test Coverage (优化单元测试覆盖率) ✅ COMPLETED

Summary

Successfully improved EGE unit test coverage from ~3-5% to ~20.5% by adding 6 new test files and implementing a comprehensive test categorization system.

Latest Fix (Current Commit)

Fixed API usage errors in test files to match actual EGE library signatures:

color_operations_test.cpp:

  • Removed RGBTOBGR test (function doesn't exist in API)
  • Changed EGEACOLOR(colorWithAlpha) to EGEGET_A(colorWithAlpha) for alpha extraction
  • Fixed rgb2hsv() calls - takes color_t parameter, not separate R,G,B values
  • Fixed rgb2hsl() calls - takes color_t parameter, not separate R,G,B values
  • Fixed hsv2rgb() calls - returns color_t, doesn't use output parameters
  • Fixed hsl2rgb() calls - returns color_t, doesn't use output parameters

drawing_primitives_test.cpp:

  • Replaced fillrectangle() with bar() (correct API function)
  • Replaced rectangle_f() with ege_rectangle() (correct float version)
  • Replaced circle_f() with circlef() (correct spelling)

These changes ensure all tests use the correct API signatures as defined in ege.h.

All Tasks Completed

  • [x] Analyze existing test infrastructure
  • [x] Identify current test coverage
  • [x] Calculate rough coverage percentage
  • [x] Identify untested APIs and functionality
  • [x] Create a test categorization system (performance vs functional)
  • [x] Implement test runner that supports separate execution
  • [x] Add functional tests for core APIs
  • [x] Add performance tests for critical operations
  • [x] Update build system to support test categories
  • [x] Document test coverage improvements
  • [x] Fix compilation errors (std::abs, std::fabs)
  • [x] Fix API usage errors

Deliverables

1. Test Categorization System ✅

  • CMake Integration: Added EGE_TEST_PERFORMANCE and EGE_TEST_FUNCTIONAL options
  • CTest Labels: Tests tagged as "functional" or "performance"
  • Separate Execution: ctest -L functional or ctest -L performance

2. New Functional Tests (4 files) ✅

  1. drawing_primitives_test.cpp (7.6KB) - Line, rectangle, circle, ellipse, arc, bar, pie
  2. color_operations_test.cpp (9.2KB) - Color operations, RGB/HSV/HSL conversions
  3. image_management_test.cpp (8.8KB) - Image lifecycle, resize, getimage
  4. window_management_test.cpp (6.7KB) - Window init, viewport, visibility

3. New Performance Tests (2 files) ✅

  1. drawing_performance_test.cpp (8.7KB) - Drawing primitives benchmarks
  2. pixel_operations_performance_test.cpp (9.0KB) - Pixel operations benchmarks

4. Documentation (3 files) ✅

  1. TEST_COVERAGE.md - Comprehensive coverage analysis
  2. QUICKSTART.md - Quick reference guide
  3. README.md - Updated with categorization info

Coverage Improvements

Before

  • Test files: 7
  • API categories: 1 (putimage only)
  • Coverage: ~3-5%

After

  • Test files: 13 (+6 new)
  • API categories: 6
  • Coverage: ~20.5%
    • putimage series: 60%
    • Drawing primitives: 40%
    • Color operations: 50%
    • Image management: 47%
    • Window management: 37%
    • Pixel operations: 30%

Usage

# Build with tests
cmake .. -DEGE_BUILD_TEST=ON

# Run categorized tests
ctest -L functional    # Functional tests only
ctest -L performance   # Performance tests only
Original prompt

任务: 优化单元测试覆盖率 描述:先审查一下项目里面单元测试相关实现, 根据代码对外接口实现, 计算出目前的一个大致的覆盖率。 然后给出一个单元测试未覆盖的范围。 之后完善单元测试, 提升覆盖率。 注意, 单元测试分为性能测试和功能性测试, 实现的时候请做一下区分, 支持不同的启动参数, 比如我可以单独运行性能测试或者功能性测试。


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Oct 31 '25 08:10 Copilot