Skip to content

Rework test suite - #94

Merged
danielchalmers merged 2 commits into
mainfrom
claude/epic-wright-08eda6
Jul 3, 2026
Merged

danielchalmers merged 2 commits into
mainfrom
claude/epic-wright-08eda6

Conversation

@danielchalmers

Copy link
Copy Markdown
Owner

A full pass over JournalApp.Tests aimed at a stronger suite, not a higher test count. The suite ends up with fewer test methods and ~350 fewer lines of test code, yet covers more real behavior and has zero skipped tests.

Results

Before After
Test methods 135 127
Runtime cases 189 (1 skipped) 238 (0 skipped)
Test code 3,766 lines 3,410 lines

All 238 pass locally.

Removed weak tests

  • 12 framework-not-app tests in DataIntegrityTests that only verified EF/SQLite round-trips a nullable/typed column (null string/decimal, boundary doubles, DateOnly, a bool predicate) with no app logic in the path — already covered by the backup round-trip tests.
  • 2 tautological tests in DataPointServiceTests.
  • The phantom [Fact(Skip)] ReplaceDbSets_IsAtomic_RollsBackOnError stub — rollback is genuinely tested by ReplaceDbSets_WithPartialFailure_RollsBackCompletely.

Consolidated (~30 near-duplicate [Fact]s → [Theory] blocks)

DataPointServiceTests (703 → ~215 lines), AppDbContextTests, AppDataServiceTests, and ImportExportTests (shared MemoryStream helper). Every meaningful assertion is retained; the medication-boundary test is now deterministic instead of DateTime.Now-based.

Reworked

  • DataPoint_PreservesGuidOnSave had a dead conditional (DataPoint.Create never sets a Guid, so the branch never ran) — now asserts an explicit key survives the round-trip.
  • Tightened AddCategory index assertion from >0 to the exact value.

Added branch coverage for previously-dark logic

Enabled by [assembly: InternalsVisibleTo("JournalApp.Tests")]:

  • TrendChartPoint mood/med-dose mapping — guards the ChartEmojis list against silently diverging from DataPoint.Moods (they're maintained by hand with nothing linking them, so a reorder corrupts every mood chart).
  • GridMonth calendar leading-blank offset math across first-day-of-week cultures.
  • CalendarService point filtering and deliberate duplicate-date tolerance.
  • KeyEventService back-button stack (peek-not-pop, empty-stack underflow guard).
  • ColorUtil gradient/complementary math, model formatting/predicates, PreferenceService success branches, and the import-wizard warning / success / read-failure branches.

Deliberately not added (to avoid fluff)

  • An export "user cancels save" test — while writing it I found FileSaverResult(null, null) is treated as success, so the wizard's "cancelled" else branch is unreachable dead code and a real cancel already surfaces as an exception the existing failure test covers.
  • JaMessageBox bUnit tests — the tri-state result mapping is already exercised at the service layer via TestDialogService, and these MudBlazor-overlay component tests are brittle.

Verification

global.json pins SDK 10.0.200 (dev machine has 10.0.301), so I ran the suite with a temporary rollForward adjustment and reverted it — the only non-test change is the InternalsVisibleTo assembly attribute.

Full pass over JournalApp.Tests aimed at a stronger suite, not a higher
test count. Net result: fewer test methods and ~350 fewer lines of test
code, yet more real behavior covered and zero skipped tests.

Remove weak tests:
- Delete 12 framework-not-app tests in DataIntegrityTests that only
  verified EF/SQLite round-trips a nullable/typed column (already covered
  by the backup round-trip tests).
- Delete 2 tautological tests in DataPointServiceTests.
- Delete the phantom [Fact(Skip)] ReplaceDbSets_IsAtomic_RollsBackOnError
  stub (rollback is already tested by ReplaceDbSets_WithPartialFailure).

Consolidate ~30 near-duplicate [Fact]s into [Theory] blocks across
DataPointServiceTests (703 -> ~215 lines), AppDbContextTests,
AppDataServiceTests, and ImportExportTests (shared MemoryStream helper),
keeping every meaningful assertion.

Rework misleading tests:
- DataPoint_PreservesGuidOnSave had a dead conditional; now asserts an
  explicit key survives the round-trip.
- Tighten AddCategory index assertion from >0 to exact value.

Add branch-focused coverage for previously untested logic:
- TrendChartPoint mood/med-dose mapping (guards ChartEmojis vs
  DataPoint.Moods divergence).
- GridMonth calendar offset math across first-day-of-week cultures.
- CalendarService point filtering and duplicate-date tolerance.
- KeyEventService back-button stack (peek-not-pop, empty-stack guard).
- ColorUtil gradient/complementary math, model formatting/predicates,
  PreferenceService success branches, and import-wizard warning/success/
  read-failure branches.

Add [assembly: InternalsVisibleTo("JournalApp.Tests")] to reach the
internal logic above.
@danielchalmers danielchalmers changed the title Shore up the test suite: prune weak tests, add branch coverage Rework test suite Jul 3, 2026
The doc-comment summaries and a couple of inline notes were wrapped at a
line-width boundary, splitting sentences mid-thought. Reflow them so each
sentence sits on its own line, matching the project's comment style.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reworks the JournalApp.Tests suite to reduce duplication while increasing meaningful behavioral coverage, and enables tests to exercise selected internal logic in JournalApp via InternalsVisibleTo.

Changes:

  • Added [assembly: InternalsVisibleTo("JournalApp.Tests")] so tests can cover internal, regression-prone logic without expanding the public API.
  • Consolidated many near-duplicate tests into theory-based cases and removed weak/tautological/skipped tests, while adding targeted coverage for previously untested branches (calendar grid math, trend mapping, back-button stack behavior, import wizard flows, preference parsing).
  • Refactored several tests to be more deterministic (e.g., stream-based backup corruption tests, fixed-date scenarios) and to assert more precise outcomes.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
JournalApp/Properties/AssemblyInfo.cs Exposes internal members to the test assembly to enable deeper branch coverage without changing the app’s public surface.
JournalApp.Tests/Utilities/ColorUtilTests.cs Adds focused tests for color gradient and complementary-hue logic used by the mood palette.
JournalApp.Tests/Pages/Trends/TrendChartPointTests.cs Adds tests for internal trend-chart mapping (mood index mapping, med dose logic, pass-through fields).
JournalApp.Tests/Pages/Calendar/GridMonthTests.cs Adds tests for calendar grid layout math across first-day-of-week cultures and emoji placement.
JournalApp.Tests/MarkupUtilTests.cs Extends ToClassName coverage for leading/all-invalid character inputs.
JournalApp.Tests/KeyEventServiceTests.cs Adds tests for back-button action stack behavior (depth tracking, peek-not-pop, empty-stack guard).
JournalApp.Tests/ImportExportTests.cs Refactors archive failure tests to use in-memory streams and shared helpers for clearer, faster negative-path coverage.
JournalApp.Tests/DateUtilTests.cs Adds edge-case coverage for DatesTo when start=end and start>end.
JournalApp.Tests/Data/PreferenceServiceTests.cs Adds tests for valid stored theme parsing, export date parsing, and mood-color behavior for unknown/excluded emojis.
JournalApp.Tests/Data/ModelTests.cs Adds tests for model formatting/predicate logic that feeds UI/layout (category formatting, SingleLine, note timestamp predicate).
JournalApp.Tests/Data/DataPointServiceTests.cs Consolidates many value-manipulation tests into theories and keeps explicit guard/exception behavior covered.
JournalApp.Tests/Data/DataIntegrityTests.cs Removes framework-only persistence checks, tightens intent, and replaces the GUID persistence test with an explicit-key round-trip assertion.
JournalApp.Tests/Data/CalendarServiceTests.cs Adds coverage for the grid-year mood-point filtering logic and duplicate-date tolerance.
JournalApp.Tests/Data/AppDbContextTests.cs Consolidates disabled/deleted-category cases into theories and tightens index assertions.
JournalApp.Tests/Data/AppDataUIServiceTests.cs Adds import-wizard tests for warning/abort, end-to-end success, and read-archive failure branches.
JournalApp.Tests/Data/AppDataServiceTests.cs Removes skipped atomicity stub, consolidates preference-restore tests, and expands backup/restore assertions (e.g., deleted flag).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danielchalmers
danielchalmers merged commit 2caca76 into main Jul 3, 2026
2 checks passed
@danielchalmers
danielchalmers deleted the claude/epic-wright-08eda6 branch July 3, 2026 16:11
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