[Test Improver] Add unit tests for TimeSpanParser#7858
Merged
Evangelink merged 1 commit intoApr 27, 2026
Conversation
Add 116 tests covering TimeSpanParser.TryParse and Parse methods: - Null/empty/whitespace inputs return false / throw FormatException - No suffix parses as milliseconds (e.g. '5400000' = 5400 seconds) - ms/mil suffix (case-insensitive) parses as milliseconds - s/sec/secs/second/seconds suffix parses as seconds - m/min/mins/minute/minutes suffix parses as minutes - h/hour/hours suffix parses as hours - d/day/days suffix parses as days - Decimal values (e.g. '1.5s') - Space between value and suffix (regex allows \s*) - TryParse and Parse are consistent for valid inputs - Invalid inputs (non-numeric, no leading digit) return false / throw Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new unit test suite for Microsoft.Testing.Platform.Helpers.TimeSpanParser, which is used by Microsoft.Testing.Platform to parse human-friendly timeout/duration strings.
Changes:
- Introduces
TimeSpanParserTestscoveringTryParseandParsefor common suffixes (ms/s/m/h/d) and invalid inputs. - Adds coverage for whitespace inputs, “no suffix” inputs (milliseconds), and some decimal/whitespace-before-suffix scenarios.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TimeSpanParserTests.cs | New MSTest-based unit tests for TimeSpanParser parsing behaviors |
Copilot's findings
Comments suppressed due to low confidence (1)
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TimeSpanParserTests.cs:165
TryParse_SpaceBetweenValueAndSuffix_ParsesCorrectlydoesn't validate the parsed value/unit, andexpectedMsis unused (also misleading for inputs like "5 m" which should be minutes). Consider asserting the expectedTimeSpanfor each case (or renaming the parameter) so the test verifies behavior rather than only non-zero output.
[TestMethod]
[DataRow("5 s", 5)]
[DataRow("5 ms", 5)]
[DataRow("5 m", 5)]
public void TryParse_SpaceBetweenValueAndSuffix_ParsesCorrectly(string input, double expectedMs)
{
// The regex allows optional whitespace before suffix
bool result = TimeSpanParser.TryParse(input, out TimeSpan value);
Assert.IsTrue(result);
Assert.AreNotEqual(TimeSpan.Zero, value);
}
- Files reviewed: 1/1 changed files
- Comments generated: 4
YuliiaKovalova
approved these changes
Apr 27, 2026
5 tasks
This was referenced May 14, 2026
2 tasks
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.
Fixes #7852