Skip to content

Conversation

@thomhurst
Copy link
Owner

Fixes #2794

thomhurst and others added 2 commits August 6, 2025 18:05
- Initialize TestContext.Configuration from Microsoft.Testing.Platform's IConfiguration service
- Create SkipIfNotDynamicCodeSupportedAttribute for conditional test skipping based on AOT mode
- Update ConfigurationTests to skip only in AOT mode, allowing tests to run in normal and reflection modes

This fixes the issue where TestContext.Configuration was always null even when a config file was provided.

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

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@claude
Copy link
Contributor

claude bot commented Aug 6, 2025

Claude finished @thomhurst's task —— View job


PR Review: Fix TestContext.Configuration

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze changed files for code quality and best practices
  • Check for potential bugs or issues
  • Review performance considerations
  • Examine security concerns
  • Evaluate test coverage
  • Provide comprehensive feedback

Review Findings

Code Quality & Best Practices

SkipIfNotDynamicCodeSupportedAttribute.cs:

  • ✅ Well-structured attribute following TUnit patterns
  • ✅ Proper inheritance from SkipAttribute
  • ✅ Good use of conditional compilation (#if NET)
  • ✅ Appropriate use of RuntimeFeature.IsDynamicCodeSupported
  • ✅ Clear naming and purpose

TUnitServiceProvider.cs:

  • ✅ Clean initialization of TestContext.Configuration at line 63
  • ✅ Uses dependency injection pattern correctly
  • ✅ Proper placement in constructor after getting configuration service

ConfigurationTests.cs:

  • ✅ Good use of the new skip attribute
  • ✅ Clear test structure and assertions

🐛 Potential Issues

  • Minor: No validation that configuration parameter is not null in TUnitServiceProvider constructor before creating ConfigurationAdapter
  • Low Risk: The ConfigurationAdapter assumes the Microsoft Testing Platform IConfiguration will never return null, but this is likely safe given the platform's design

Performance Considerations

  • Excellent: RuntimeFeature.IsDynamicCodeSupported check is compile-time/startup-time only
  • ✅ Configuration initialization happens once per test session
  • ✅ No performance overhead during test execution

🔒 Security Concerns

  • No security issues identified
  • Configuration access is read-only
  • No exposure of sensitive data in test output
  • Uses platform-provided configuration abstraction

🧪 Test Coverage

  • Good coverage for the configuration feature:
    • Basic configuration value retrieval
    • Missing key handling (returns null)
    • Nested configuration values with colon notation
  • ✅ Appropriate use of skip attribute for AOT scenarios
  • ✅ Tests match the configuration in testconfig.json

🎯 Recommendations

  1. Consider adding null check in TUnitServiceProvider.cs:63:

    var configuration = frameworkServiceProvider.GetConfiguration() 
        ?? throw new InvalidOperationException("Configuration service not available");
    TestContext.Configuration = new ConfigurationAdapter(configuration);
  2. Documentation: The configuration feature is well-documented in IConfiguration interface with clear examples

📋 Summary

This is a solid implementation that addresses the TestContext.Configuration initialization issue. The code follows good practices, has appropriate test coverage, and includes thoughtful AOT/dynamic code support handling. The fix ensures configuration is available early in the test lifecycle.

Recommendation: ✅ Approve - This PR successfully fixes the configuration initialization with minimal risk and good design.


@claude
Copy link
Contributor

claude bot commented Aug 6, 2025

Claude finished @thomhurst's task —— View job


PR Review: Fix TestContext.Configuration

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze changed files for code quality and best practices
  • Check for potential bugs or issues
  • Review performance considerations
  • Examine security concerns
  • Evaluate test coverage
  • Provide comprehensive feedback

Review Findings

Code Quality & Best Practices

SkipIfNotDynamicCodeSupportedAttribute.cs:

  • ✅ Well-structured attribute following TUnit patterns
  • ✅ Proper inheritance from SkipAttribute
  • ✅ Good use of conditional compilation (#if NET)
  • ✅ Appropriate use of RuntimeFeature.IsDynamicCodeSupported
  • ✅ Clear naming and purpose

TUnitServiceProvider.cs:

  • ✅ Clean initialization of TestContext.Configuration at line 63
  • ✅ Uses dependency injection pattern correctly
  • ✅ Proper placement in constructor after getting configuration service

ConfigurationTests.cs:

  • ✅ Good use of the new skip attribute
  • ✅ Clear test structure and assertions

🐛 Potential Issues

  • Minor: No validation that configuration parameter is not null in TUnitServiceProvider constructor before creating ConfigurationAdapter
  • Low Risk: The ConfigurationAdapter assumes the Microsoft Testing Platform IConfiguration will never return null, but this is likely safe given the platform's design

Performance Considerations

  • Excellent: RuntimeFeature.IsDynamicCodeSupported check is compile-time/startup-time only
  • ✅ Configuration initialization happens once per test session
  • ✅ No performance overhead during test execution

🔒 Security Concerns

  • No security issues identified
  • Configuration access is read-only
  • No exposure of sensitive data in test output
  • Uses platform-provided configuration abstraction

🧪 Test Coverage

  • Good coverage for the configuration feature:
    • Basic configuration value retrieval
    • Missing key handling (returns null)
    • Nested configuration values with colon notation
  • ✅ Appropriate use of skip attribute for AOT scenarios
  • ✅ Tests match the configuration in testconfig.json

🎯 Recommendations

  1. Consider adding null check in TUnitServiceProvider.cs:63:

    var configuration = frameworkServiceProvider.GetConfiguration() 
        ?? throw new InvalidOperationException("Configuration service not available");
    TestContext.Configuration = new ConfigurationAdapter(configuration);
  2. Documentation: The configuration feature is well-documented in IConfiguration interface with clear examples

📋 Summary

This is a solid implementation that addresses the TestContext.Configuration initialization issue. The code follows good practices, has appropriate test coverage, and includes thoughtful AOT/dynamic code support handling. The fix ensures configuration is available early in the test lifecycle.

Recommendation: ✅ Approve - This PR successfully fixes the configuration initialization with minimal risk and good design.


@thomhurst thomhurst merged commit 4b8a2de into main Aug 6, 2025
8 checks passed
@thomhurst thomhurst deleted the bug/2794 branch August 6, 2025 17:50
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.

TestContext.Configuration seems to always be null (v0.50+)

1 participant