Skip to content

[test-improver] test: add StringComparison overload and null-handling tests for Assert.StartsWith/EndsWith#8781

Merged
Evangelink merged 1 commit into
mainfrom
test-assist/starts-ends-with-string-comparison-30ff8071e45daa3b
Jun 3, 2026
Merged

[test-improver] test: add StringComparison overload and null-handling tests for Assert.StartsWith/EndsWith#8781
Evangelink merged 1 commit into
mainfrom
test-assist/starts-ends-with-string-comparison-30ff8071e45daa3b

Conversation

@Evangelink

@Evangelink Evangelink commented Jun 2, 2026

Copy link
Copy Markdown
Member

🤖 Test Improver — automated AI assistant for test improvements.

Goal and Rationale

Assert.StartsWith, Assert.DoesNotStartWith, Assert.EndsWith, and Assert.DoesNotEndWith each have two overloads: one defaulting to StringComparison.Ordinal and one accepting an explicit StringComparison. The existing tests in AssertTests.StartsWithEndsWith.cs only exercised the default Ordinal path — the StringComparison overloads and null parameter handling were completely untested.

These are real logic paths worth testing:

  • The StringComparison overload is the core of case-insensitive string assertion, commonly used in multi-culture test suites.
  • Null handling follows CheckParameterNotNull which throws a specific AssertFailedException message — a contract worth verifying.

Approach

Added 18 new tests to AssertTests.StartsWithEndsWith.cs covering:

Category Count Methods
OrdinalIgnoreCase success (case mismatch / exact match passes) 6 StartsWith × 2, DoesNotStartWith × 1, EndsWith × 2, DoesNotEndWith × 1
OrdinalIgnoreCase failure message includes comparison: 4 all four methods
Null valueAssertFailedException 4 all four methods
Null prefix/suffix → AssertFailedException 4 all four methods

Coverage Impact

File Before After
AssertTests.StartsWithEndsWith.cs 8 tests 26 tests (+18)
Assert.StartsWith.cs / Assert.EndsWith.cs StringComparison overloads untested now covered

Trade-offs

  • Tests are straightforward string comparisons — low maintenance burden.
  • Null-handling tests depend on the exact exception message format; if the format changes, these tests will catch the regression intentionally.

Reproducibility

./build.sh --projects "$(pwd)/test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj" -test

Test Status

✅ All TestFramework.UnitTests tests pass (net8.0 and net9.0)

Generated by Test Improver · sonnet46 4.5M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/test-improver.md@main

…t.StartsWith/EndsWith

Add 16 new tests covering previously untested code paths:
- StringComparison.OrdinalIgnoreCase overloads for all four methods
  (StartsWith, DoesNotStartWith, EndsWith, DoesNotEndWith)
- Null parameter handling (null value and null prefix/suffix) for all four methods

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 2, 2026 23:40
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 2, 2026

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 missing unit-test coverage for the StringComparison overloads (and null-parameter behavior) of MSTest’s string boundary assertions in src/TestFramework, ensuring structured failure messages and CheckParameterNotNull contracts are exercised.

Changes:

  • Added OrdinalIgnoreCase coverage for Assert.StartsWith / Assert.EndsWith success and for failure messages including the comparison: evidence line.
  • Added null-parameter tests for value and prefix/suffix parameters across StartsWith, DoesNotStartWith, EndsWith, and DoesNotEndWith.
  • Validated expected/actual payload values for new structured-failure cases.
Show a summary per file
File Description
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWithEndsWith.cs Adds tests covering StringComparison overload behavior and null-parameter exception contracts for StartsWith/EndsWith assertions.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

@Evangelink Evangelink marked this pull request as ready for review June 3, 2026 08:08
@Evangelink Evangelink enabled auto-merge (squash) June 3, 2026 10:55
@Evangelink Evangelink merged commit 8e0783c into main Jun 3, 2026
40 checks passed
@Evangelink Evangelink deleted the test-assist/starts-ends-with-string-comparison-30ff8071e45daa3b branch June 3, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants