Skip to content

Parameterize truth-table and boundary unit tests (#118)#119

Merged
almothafar merged 1 commit into
masterfrom
118-parameterize-unit-tests
Jul 10, 2026
Merged

Parameterize truth-table and boundary unit tests (#118)#119
almothafar merged 1 commit into
masterfrom
118-parameterize-unit-tests

Conversation

@almothafar

Copy link
Copy Markdown
Owner

Closes #118.

What

Convert the repetitive, data-driven cases in the five plain-JVM test classes to JUnit 4's built-in @RunWith(Parameterized.class), using @RunWith(Enclosed.class) on each outer class so a single file can host several parameterized tables plus the named tests that still read better as prose.

No new dependency (Parameterized/Enclosed ship with the junit:junit:4.13.2 we already use) and no production code changes — tests only.

The pattern

Each table becomes a public static nested class with @Parameter fields, a @Parameters data method (with a name = "..." label so rows are readable in the report), and one @Test. A leading String label column carries the per-row intent that used to live in method names / comments.

Where it was — and wasn't — applied

Class Parameterized Left as named @Test (intent > data)
NotificationServiceTest isWithinTimeRange, alertsAllowedNow
SystemServiceTest estimateFullCapacityMah, designCapacityMahFromMicroAmpHours
BatteryHealthTrackerTest computeMeasuredHealth, gradeForPercentage, isValidDesignCapacity, isEstimateImplausible accruePartialCycles (stateful, two-step)
TemperatureUtilsTest int conversions, isAtOrAboveThreshold, isBelowResetThreshold float rounding, °C↔°F round-trip
BatteryDOTest getBatteryPercentage builder chaining, health-status enum, 1/3 precision

Per the issue guidance, tables were not forced onto cases where a descriptive method name or a distinct delta/assertion documents the behaviour better than a data row.

The Robolectric receiver tests (PowerConnectionReceiverTest, BatteryLevelReceiverTest, BatteryHealthTrackerStateTest) are untouched — a JUnit 4 class allows only one runner, so they'd need ParameterizedRobolectricTestRunner, which wasn't worth it here.

Testing

./gradlew testDebugUnitTestBUILD SUCCESSFUL, all classes green (0 failures / 0 errors). Row counts after conversion: NotificationService 16, SystemService 23, BatteryHealthTracker 34, TemperatureUtils 19, BatteryDO 13.

🤖 Generated with Claude Code

Convert the repetitive, data-driven cases in the plain-JVM test classes to
JUnit 4 Parameterized runners, using @RunWith(Enclosed.class) so each file can
host several parameterized tables alongside the named tests that still read
better as prose. No new dependency and no production code changes.

- NotificationServiceTest: isWithinTimeRange + alertsAllowedNow tables
- SystemServiceTest: estimateFullCapacityMah + designCapacityMahFromMicroAmpHours
- BatteryHealthTrackerTest: computeMeasuredHealth, gradeForPercentage,
  isValidDesignCapacity, isEstimateImplausible (accruePartialCycles stays named)
- TemperatureUtilsTest: int conversions + threshold checks (float rounding /
  round-trip stay named)
- BatteryDOTest: getBatteryPercentage table (builder / enum / precision stay named)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@almothafar almothafar merged commit 77ab426 into master Jul 10, 2026
2 checks passed
@almothafar almothafar deleted the 118-parameterize-unit-tests branch July 10, 2026 19:03
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.

Parameterize repetitive unit tests (truth tables / boundary checks)

1 participant