Skip to content

[Test Improver] Add unit tests for TimeSpanParser#7858

Merged
Evangelink merged 1 commit into
mainfrom
test-assist/timespan-parser-unit-tests-eabf1f50849ca30c
Apr 27, 2026
Merged

[Test Improver] Add unit tests for TimeSpanParser#7858
Evangelink merged 1 commit into
mainfrom
test-assist/timespan-parser-unit-tests-eabf1f50849ca30c

Conversation

@Evangelink

@Evangelink Evangelink commented Apr 27, 2026

Copy link
Copy Markdown
Member

Fixes #7852

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>
Copilot AI review requested due to automatic review settings April 27, 2026 07:57
@Evangelink Evangelink enabled auto-merge (squash) April 27, 2026 07:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 TimeSpanParserTests covering TryParse and Parse for 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_ParsesCorrectly doesn't validate the parsed value/unit, and expectedMs is unused (also misleading for inputs like "5 m" which should be minutes). Consider asserting the expected TimeSpan for 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

@Evangelink Evangelink merged commit b6d6b9d into main Apr 27, 2026
49 checks passed
@Evangelink Evangelink deleted the test-assist/timespan-parser-unit-tests-eabf1f50849ca30c branch April 27, 2026 10:02
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.

[Test Improver] Add unit tests for TimeSpanParser

3 participants