Repository navigation
Rework test suite - #94
Merged
Merged
Conversation
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.
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.
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A full pass over
JournalApp.Testsaimed 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
All 238 pass locally.
Removed weak tests
DataIntegrityTeststhat 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.DataPointServiceTests.[Fact(Skip)]ReplaceDbSets_IsAtomic_RollsBackOnErrorstub — rollback is genuinely tested byReplaceDbSets_WithPartialFailure_RollsBackCompletely.Consolidated (~30 near-duplicate
[Fact]s →[Theory]blocks)DataPointServiceTests(703 → ~215 lines),AppDbContextTests,AppDataServiceTests, andImportExportTests(sharedMemoryStreamhelper). Every meaningful assertion is retained; the medication-boundary test is now deterministic instead ofDateTime.Now-based.Reworked
DataPoint_PreservesGuidOnSavehad a dead conditional (DataPoint.Createnever sets a Guid, so the branch never ran) — now asserts an explicit key survives the round-trip.AddCategoryindex assertion from>0to the exact value.Added branch coverage for previously-dark logic
Enabled by
[assembly: InternalsVisibleTo("JournalApp.Tests")]:TrendChartPointmood/med-dose mapping — guards theChartEmojislist against silently diverging fromDataPoint.Moods(they're maintained by hand with nothing linking them, so a reorder corrupts every mood chart).GridMonthcalendar leading-blank offset math across first-day-of-week cultures.CalendarServicepoint filtering and deliberate duplicate-date tolerance.KeyEventServiceback-button stack (peek-not-pop, empty-stack underflow guard).ColorUtilgradient/complementary math, model formatting/predicates,PreferenceServicesuccess branches, and the import-wizard warning / success / read-failure branches.Deliberately not added (to avoid fluff)
FileSaverResult(null, null)is treated as success, so the wizard's "cancelled"elsebranch is unreachable dead code and a real cancel already surfaces as an exception the existing failure test covers.JaMessageBoxbUnit tests — the tri-state result mapping is already exercised at the service layer viaTestDialogService, and these MudBlazor-overlay component tests are brittle.Verification
global.jsonpins SDK10.0.200(dev machine has10.0.301), so I ran the suite with a temporaryrollForwardadjustment and reverted it — the only non-test change is theInternalsVisibleToassembly attribute.