Skip to content

Tests: Increase code coverage#4

Merged
ScarletKuro merged 3 commits intomasterfrom
copilot/add-codecov-badge-and-tests
Jan 15, 2026
Merged

Tests: Increase code coverage#4
ScarletKuro merged 3 commits intomasterfrom
copilot/add-codecov-badge-and-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 15, 2026

Codecov reports ~50% coverage for the converter implementations. Added standalone tests for each converter to exercise all code paths.

Changes

  • README: Added codecov badge
  • ConverterTests.cs: Added 43 unit tests targeting the 8 converter classes directly:
    • DateTimeConverter, DateTimeNullableConverter
    • DateTimeOffsetConverter, DateTimeOffsetNullableConverter
    • DateOnlyConverter, DateOnlyNullableConverter
    • TimeOnlyConverter, TimeOnlyNullableConverter

Test Coverage

Each converter test suite covers:

  • Write/Read methods with custom format strings
  • Fallback behavior when format parsing fails (falls back to GetDateTime(), GetDateTimeOffset())
  • Null token handling for nullable types
  • Error paths (invalid formats that throw JsonException)
  • Round-trip serialization/deserialization
[Fact]
public void DateTimeConverter_Read_InvalidFormat_FallbackToGetDateTime()
{
    var options = new JsonSerializerOptions
    {
        Converters = { new JsonDateTimeConverterAttribute("yyyy-MM-dd").CreateConverter(typeof(DateTime)) }
    };
    var json = "\"2023-10-15T14:30:45Z\""; // ISO format doesn't match custom format

    var result = JsonSerializer.Deserialize<DateTime>(json, options);

    Assert.Equal(new DateTime(2023, 10, 15, 14, 30, 45, DateTimeKind.Utc), result);
}

All 65 tests pass (43 new + 22 existing).

Original prompt

Add codecov badge in readme:
codecov

Also, codecov shows very low coverage for:
Scarlet.System.Text.Json.DateTimeConverter/src/Scarlet.System.Text.Json.DateTimeConverter/Converters

DateOnlyConverter.cs
14 7 2 5
50.00%
DateOnlyNullableConverter.cs
14 6 4 4
42.86%
DateTimeConverter.cs
10 7 2 1
70.00%
DateTimeNullableConverter.cs
14 6 4 4
42.86%
DateTimeOffsetConverter.cs
10 7 2 1
70.00%
DateTimeOffsetNullableConverter.cs
14 6 4 4
42.86%
TimeOnlyConverter.cs
14 7 2 5
50.00%
TimeOnlyNullableConverter.cs
14 6 4 4
42.86%

Subtotal
104 52 24 28

We should add standalone tests for each of this converters seperatly with full coverage of all if branches etc


✨ 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 AI and others added 2 commits January 15, 2026 21:33
Co-authored-by: ScarletKuro <19953225+ScarletKuro@users.noreply.github.com>
- Added 43 new tests covering all 8 converters
- Tests cover Read/Write methods, null handling, format validation
- Tests cover fallback scenarios and error paths
- All tests pass successfully

Co-authored-by: ScarletKuro <19953225+ScarletKuro@users.noreply.github.com>
Copilot AI changed the title [WIP] Add codecov badge to README and improve test coverage Add codecov badge and comprehensive converter unit tests Jan 15, 2026
Copilot AI requested a review from ScarletKuro January 15, 2026 21:37
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.26%. Comparing base (0a089ba) to head (3bd3c2b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master       #4       +/-   ##
===========================================
+ Coverage   59.75%   79.26%   +19.51%     
===========================================
  Files          13       13               
  Lines         164      164               
  Branches       39       39               
===========================================
+ Hits           98      130       +32     
+ Misses         36       20       -16     
+ Partials       30       14       -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ScarletKuro ScarletKuro marked this pull request as ready for review January 15, 2026 21:49
@ScarletKuro ScarletKuro changed the title Add codecov badge and comprehensive converter unit tests Tests: Increase code coverage Jan 15, 2026
@ScarletKuro ScarletKuro merged commit eed51e4 into master Jan 15, 2026
3 checks passed
@ScarletKuro ScarletKuro deleted the copilot/add-codecov-badge-and-tests branch January 15, 2026 21: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.

2 participants