Skip to content

Daily Test Coverage Improver - OpenAPI Routing Schema Tests#31

Merged
dsyme merged 1 commit intomainfrom
test-coverage/openapi-routing-schema-tests-2ba6d55547b43266
Oct 23, 2025
Merged

Daily Test Coverage Improver - OpenAPI Routing Schema Tests#31
dsyme merged 1 commit intomainfrom
test-coverage/openapi-routing-schema-tests-2ba6d55547b43266

Conversation

@dsyme
Copy link
Contributor

@dsyme dsyme commented Oct 23, 2025

Summary

This PR adds comprehensive tests for the OpenAPI routing schema generation code in Oxpecker.OpenApi/Routing.fs, significantly improving test coverage of previously untested code paths.

Changes Made

  • Added 13 new test cases to tests/Oxpecker.OpenApi.Tests/Routing.Tests.fs
  • Tests now properly exercise the getSchema function for all parameter type format specifiers:
    • %s (string) - %i (int) - %b (bool) - %c (char)
    • %d (int64) - %f (float) - %u (uint64) - %O (Guid/object)
  • Tests verify the addOpenApiSimple type matching logic for all four type combinations:
    • unit request + unit response (InvokeUnit)
    • unit request + typed response (InvokeUnitReq)
    • typed request + unit response (InvokeUnitResp)
    • typed request + typed response (Invoke)
  • Tests execute the .WithOpenApi() configuration callbacks to exercise schema parameter generation code

Test Coverage Results

Metric Before After Change
Oxpecker.OpenApi/Routing.fs Line Coverage 31.71% 41.46% +9.76%
Oxpecker.OpenApi/Routing.fs Branch Coverage 26.67% 26.67% +0.00%
Overall Project Line Coverage 86.64% 86.91% +0.27%
Overall Project Branch Coverage 62.94% 62.94% +0.00%

Detailed Coverage Improvement

The new tests cover:

  • Lines 13-25: The getSchema function that maps format characters to OpenAPI schemas
  • Lines 32-45: The .WithOpenApi() configuration that adds parameters to operations
  • Lines 59-60: The metadata configuration in addOpenApiSimple

These were previously completely untested (0% coverage).

Replicating the Test Coverage Measurements

To replicate these coverage measurements:

# Install dependencies and build
dotnet restore Oxpecker.sln
dotnet build Oxpecker.sln --no-restore

# Run tests with coverage
dotnet test Oxpecker.sln --no-restore --no-build \
  --collect:"XPlat Code Coverage" \
  --results-directory ./coverage-results

# Install ReportGenerator (if not already installed)
dotnet tool install -g dotnet-reportgenerator-globaltool

# Generate coverage report
reportgenerator \
  -reports:"./coverage-results/**/coverage.cobertura.xml" \
  -targetdir:"./coverage-report" \
  -reporttypes:"Html;Cobertura"

# View summary
python3 -c "
import xml.etree.ElementTree as ET
tree = ET.parse('./coverage-report/Cobertura.xml')
root = tree.getroot()
line_rate = float(root.attrib.get('line-rate', 0)) * 100
branch_rate = float(root.attrib.get('branch-rate', 0)) * 100
print(f'Line Coverage: {line_rate:.2f}%')
print(f'Branch Coverage: {branch_rate:.2f}%')
"

# Open HTML report
open ./coverage-report/index.html  # macOS
# or: xdg-open ./coverage-report/index.html  # Linux

Future Improvement Opportunities

Based on the coverage analysis, other areas with low coverage that could benefit from additional tests:

  1. Oxpecker/Routing.fs - 56.76% line coverage (various routing helpers)
  2. Oxpecker.ViewEngine/Builder.fs - 51.61% line coverage (HTML builder functionality)
  3. Oxpecker/Core.fs, ModelBinder.fs, HttpContextExtensions.fs - 0% coverage (utility functions)
  4. Oxpecker.ViewEngine/IdeTweaks.fs - 0% coverage (IDE-specific helpers)

Testing Strategy

The tests use a mock IEndpointConventionBuilder to execute the configuration callbacks without requiring a full ASP.NET Core application context. This approach:

  • Allows isolated testing of the schema generation logic
  • Exercises the actual code paths without complex infrastructure
  • Validates that all type format specifiers produce appropriate OpenAPI schemas
Commands Executed
# Coverage analysis
dotnet restore Oxpecker.sln
dotnet build Oxpecker.sln --no-restore
dotnet test Oxpecker.sln --no-restore --no-build --collect:"XPlat Code Coverage" --results-directory ./coverage-results
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:"./coverage-results/**/coverage.cobertura.xml" -targetdir:"./coverage-report" -reporttypes:"Html;Cobertura"

# Test development  
git checkout -b test-coverage/openapi-routing-schema-tests
dotnet build tests/Oxpecker.OpenApi.Tests/Oxpecker.OpenApi.Tests.fsproj
dotnet test tests/Oxpecker.OpenApi.Tests/Oxpecker.OpenApi.Tests.fsproj --no-build

# Re-validate coverage improvement
dotnet test Oxpecker.sln --no-restore --no-build --collect:"XPlat Code Coverage" --results-directory ./coverage-results-after
reportgenerator -reports:"./coverage-results-after/**/coverage.cobertura.xml" -targetdir:"./coverage-report-after" -reporttypes:"Html;Cobertura"
Web Searches Performed

None

Web Pages Fetched

None

🤖 Generated with Claude Code

AI generated by Daily Test Coverage Improver

- Added 13 new tests to exercise OpenAPI schema generation code paths
- Tests now verify getSchema function for all parameter types (s, i, b, c, d, f, u, O)
- Tests exercise addOpenApiSimple type matching logic for all combinations
- Improved coverage of Oxpecker.OpenApi/Routing.fs from 31.71% to 41.46% (+9.76%)
- Overall project line coverage improved from 86.64% to 86.91% (+0.27%)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dsyme dsyme marked this pull request as ready for review October 23, 2025 03:37
@dsyme dsyme merged commit 2175623 into main Oct 23, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments