Parameterize truth-table and boundary unit tests (#118)#119
Merged
Conversation
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>
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.
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/Enclosedship with thejunit:junit:4.13.2we already use) and no production code changes — tests only.The pattern
Each table becomes a
public staticnested class with@Parameterfields, a@Parametersdata method (with aname = "..."label so rows are readable in the report), and one@Test. A leadingString labelcolumn carries the per-row intent that used to live in method names / comments.Where it was — and wasn't — applied
@Test(intent > data)NotificationServiceTestisWithinTimeRange,alertsAllowedNowSystemServiceTestestimateFullCapacityMah,designCapacityMahFromMicroAmpHoursBatteryHealthTrackerTestcomputeMeasuredHealth,gradeForPercentage,isValidDesignCapacity,isEstimateImplausibleaccruePartialCycles(stateful, two-step)TemperatureUtilsTestisAtOrAboveThreshold,isBelowResetThresholdBatteryDOTestgetBatteryPercentagePer 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 needParameterizedRobolectricTestRunner, which wasn't worth it here.Testing
./gradlew testDebugUnitTest— BUILD 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