Testing
Intellenum includes a comprehensive suite of tests that ensure its robustness and reliability. The testing strategy encompasses multiple levels, each targeting specific aspects of the codebase.
Snapshot Tests
These tests are designed to verify the correctness of code generation. They perform a deep comparison of the generated code against predefined expectations, ensuring that the code adheres to specific standards and requirements.
Key Features:
- Comprehensive Coverage: Tests cover various code generation scenarios, including generating record structs with instances and normalization, classes without converters or validation, and readonly structs with LinqToDb converters.
- Framework Support: Tests are executed for each supported framework, ensuring compatibility across different environments.
- Speed: Snapshot tests executed in the IDE complete within approximately 5 minutes.
- Thoroughness: Setting the
THOROUGH
flag in the CI build enables more extensive testing, which may take several hours to complete.
Project: tests/SnapshotTests
Example:
- Code:
tests/SnapshotTests/SnapshotTests.csproj
Consumer Tests
These tests focus on the practical application of Intellenum. They consume the ‘real’ Vogen NuGet package, verifying its functionality by exercising it via actual C# code. This approach ensures that Intellenum’s integration with real-world applications works as expected.
Key Features:
- Real-World Scenarios: Consumer tests simulate how Intellenum will be used in production, providing a practical assessment of its capabilities.
- NuGet Integration: The tests ensure seamless integration with the Vogen NuGet package, validating its compatibility with other projects.
Project: tests/ConsumerTests
Example:
- Code:
tests/ConsumerTests/ConsumerTests.csproj
Analyzer Tests
These tests validate the functionality of the Intellenum analyzer. The analyzer is responsible for identifying potential issues and suggesting improvements within the code.
Key Features:
- Code Quality: Analyzer tests contribute to maintaining the quality and consistency of the Intellenum codebase.
Project: tests/AnalyzerTests
Example:
- Code:
tests/AnalyzerTests/DoNotUseNewAnalyzerTests.cs
Example of an analyzer test:
[Fact]
public void Foo()
{
// ...
}
Intellenum Tests
These tests focus specifically on verifying the core functionalities of Intellenum, such as equality, hashing, ToString, validation, and instance fields.
Key Features:
- Core Functionality: Tests ensure that Intellenum’s fundamental operations work correctly.
- Value Object Validation: Tests validate the behavior of created value objects, confirming their expected functionality.
Project: tests/Intellenum.Tests
Example:
- Code:
tests/Intellenum.Tests/Intellenum.Tests.csproj
Example of a test:
{
// this is defined
bool r = PlanetEnum.TryParse("Brown-273400", out var p);
r.Should().BeTrue();
p.Should().Be(PlanetEnum.Jupiter);
}
{
// this is not defined
bool r = PlanetEnum.TryParse("Blue-24901", out _);
r.Should().BeFalse();
}
## Top-Level Directory Explanations
<a class='local-link directory-link' data-ref="tests/" href="#tests/">tests/</a> - This directory contains test projects for the Intellenum library.
<a class='local-link directory-link' data-ref="tests/AnalyzerTests/" href="#tests/AnalyzerTests/">tests/AnalyzerTests/</a> - Contains unit tests for the Intellenum analyzer.
<a class='local-link directory-link' data-ref="tests/ConsumerTests/" href="#tests/ConsumerTests/">tests/ConsumerTests/</a> - Contains tests for consuming the Intellenum library.
<a class='local-link directory-link' data-ref="tests/Intellenum.Tests/" href="#tests/Intellenum.Tests/">tests/Intellenum.Tests/</a> - Contains additional tests for the Intellenum library.
<a class='local-link directory-link' data-ref="tests/Shared/" href="#tests/Shared/">tests/Shared/</a> - Contains shared test files.
<a class='local-link directory-link' data-ref="tests/SnapshotTests/" href="#tests/SnapshotTests/">tests/SnapshotTests/</a> - Contains snapshot tests for the Intellenum library.
<a class='local-link directory-link' data-ref="tests/Testbench/" href="#tests/Testbench/">tests/Testbench/</a> - Contains a test bench for the Intellenum library.