| name | testing |
|---|---|
| description | Use for xUnit tests, JSON fixtures, mocks, Coverlet coverage, and scripts in Contentstack.Utils.Tests. |
- Adding or changing behavior in
Contentstack.Utilsand needing unit tests. - Debugging CI test failures on Windows (unit-test workflow).
- Generating local HTML coverage reports.
Contentstack.Utils.Tests.csproj: targets net7.0, IsPackable false, references the main library project.- Packages: xunit, xunit.runner.visualstudio, Microsoft.NET.Test.Sdk, coverlet.collector, Newtonsoft.Json (aligned with test needs).
Use these as a map of coverage areas when adding related behavior:
| Class | Focus |
|---|---|
JsonToHtmlTest |
JSON RTE → HTML |
GQLTest |
Utils.GQL / GraphQL-shaped RTE |
UtilsTest |
Core Utils APIs |
UtilsArrayStringTest |
Array/string rendering paths |
UtilsCustomRenderTest |
Custom Options / rendering |
DefaultRenderTest |
Default render behavior |
HtmlDocumentExtensionTest |
HTML document extensions |
MetadataTest |
Embedded metadata |
VariantAliasesTest |
Variant aliases / metadata tags |
- JSON files live under
Contentstack.Utils.Tests/Resources/. The csproj usesContent Include="Resources\**\*.json" CopyToOutputDirectory="PreserveNewest"so files are available at test runtime. - Checked-in fixtures:
variantsSingleEntry.json,variantsEntries.json.
- Shared expected strings/constants:
Constants/. - Parsing helpers:
Helpers/NodeParser.cs. - Test doubles in
Mocks/:CustomRenderOptionMock.cs,DefaultRenderMock.cs,EmbeddedModelMock.cs,GQLModel.cs. Follow existing patterns for new scenarios.
- From repo root:
dotnet test Contentstack.Utils.sln— runs all tests without the shell scripts (no TRX or coverage collection).
- Scripts use Coverlet’s XPlat code coverage and emit Cobertura XML (e.g.
coverage.cobertura.xmlunderTestResults). - For HTML: run
Scripts/run-test-case.sh, which invokesScripts/generate_test_report.py(Python 3, standard library only).
- GitHub Actions runs
Scripts/run-unit-test-case.shon Windows. When reproducing CI failures, use that script (or the samedotnet testarguments) from repo root.