Skip to content

[test-improver] test: add edge case tests for IgnoreStringMethodReturnValueAnalyzer - #9468

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
test-assist/ignore-string-method-edge-cases-1782516482-fa3ee30ff0b2f876
Jun 28, 2026
Merged

[test-improver] test: add edge case tests for IgnoreStringMethodReturnValueAnalyzer#9468
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
test-assist/ignore-string-method-edge-cases-1782516482-fa3ee30ff0b2f876

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal and Rationale

IgnoreStringMethodReturnValueAnalyzer (MSTEST0055) had only 5 tests, all covering the happy path (diagnostic fires / doesn't fire based on whether the result of Contains, StartsWith, or EndsWith is used). Three distinct code paths in the analyzer's guard logic were completely untested:

Untested pathGuard
Discard assignment _ = str.Contains(...)expressionStatementOperation.Operation is not IInvocationOperation early return
String method call inside a lambda block bodyExpressionStatement inside lambda — should still fire
String method result used as a receiver in a chained callIsStringMethodCall on the outer call (not a string method) — should not fire

Approach

Added three [TestMethod] entries to IgnoreStringMethodReturnValueAnalyzerTests.cs:

TestWhat it covers
WhenDiscardAssignmentIgnoresReturnValue_NoDiagnostic_ = str.Contains("Hello") → outer operation is IAssignmentOperation, not IInvocationOperation → early return, no diagnostic
WhenStringMethodReturnValueIgnoredInsideLambda_Diagnostic() => { str.Contains("Hello"); } → ExpressionStatement inside lambda body triggers diagnostic
WhenStringMethodResultUsedAsReceiverForChainedCall_NoDiagnosticstr.Contains("Hello").GetHashCode() → outermost ExpressionStatement operation is GetHashCode() on System.Boolean, not a string method → no diagnostic on Contains

Trade-offs

Purely additive — no production code changes, no new dependencies.

Test Status

All 8 tests pass (5 existing + 3 new):

Test run summary: Passed!
total: 8
failed: 0
succeeded: 8
duration: 5s 537ms

Reproducibility

.dotnet/dotnet run --project test/UnitTests/MSTest.Analyzers.UnitTests/ -f net8.0 --no-build -- \
--filter "FullyQualifiedName~IgnoreStringMethodReturnValueAnalyzerTests"

🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Test Improver workflow. · 1.1K AIC · ⌖ 25.3 AIC · ⊞ 58.2K · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

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

Add 3 edge case tests covering untested code paths in the analyzer's
guard conditions:
1. WhenDiscardAssignmentIgnoresReturnValue_NoDiagnostic
- `_ = str.Contains("test")` wraps an IAssignmentOperation (not
IInvocationOperation), so the early-return guard fires and no
diagnostic is reported.
2. WhenStringMethodReturnValueIgnoredInsideLambda_Diagnostic
- Expression statements inside a lambda block body are still
ExpressionStatement operations, so the analyzer fires inside
the lambda just as at method level.
3. WhenStringMethodResultUsedAsReceiverForChainedCall_NoDiagnostic
- `str.Contains("Hello").GetHashCode()` — the ExpressionStatement's
outermost operation is GetHashCode() on System.Boolean (not a
string method), so IsStringMethodCall returns false and no
diagnostic is reported. The Contains result IS used as a receiver.
All 8 tests pass (5 existing + 3 new).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 26, 2026 23:34
@EvangelinkAmaury Levé (Evangelink) added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 26, 2026

CopilotAI 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 additional unit-test coverage for the MSTest analyzer IgnoreStringMethodReturnValueAnalyzer (MSTEST0055) to cover previously untested guard/shape scenarios, without changing production analyzer behavior.

Changes:

  • Added a test ensuring discard assignments (_ = str.Contains(...)) do not produce MSTEST0055 diagnostics.
  • Added a test ensuring ignored string-method return values inside a lambda block body do produce diagnostics.
  • Added a test ensuring chained calls where the string method result is used as a receiver (e.g. str.Contains(...).GetHashCode()) do not produce diagnostics.
Show a summary per file
FileDescription
test/UnitTests/MSTest.Analyzers.UnitTests/IgnoreStringMethodReturnValueAnalyzerTests.csAdds three new test cases covering discard assignment, lambda-body expression statements, and chained-call receiver usage scenarios for MSTEST0055.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Low

@EvangelinkAmaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jun 28, 2026
@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review June 28, 2026 04:54
@Evangelink

This comment has been minimized.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Note

🤖 Automated review by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Expert Review — PR #9468

Reviewed against all 22 dimensions. Changed file: test/UnitTests/MSTest.Analyzers.UnitTests/IgnoreStringMethodReturnValueAnalyzerTests.cs


Verdict table

#DimensionResult
1Algorithmic Correctness✅ LGTM
2Threading & ConcurrencyN/A
3Security & IPC Contract SafetyN/A
4Public API & Binary CompatibilityN/A
5Performance & AllocationsN/A
6Cross-TFM CompatibilityN/A
7Resource & IDisposable ManagementN/A
8Defensive Coding at BoundariesN/A
9Localization & ResourcesN/A
10Test Isolation✅ LGTM
11Assertion Quality✅ LGTM
12Flakiness Patterns✅ LGTM
13Test Completeness & Coverage✅ LGTM
14Data-Driven Test CoverageN/A
15Code Structure & Simplification✅ LGTM
16Naming & Conventions⚠️ NIT (see inline)
17Documentation Accuracy⚠️ NIT (see inline)
18Analyzer & Code Fix Quality✅ LGTM
19IPC Wire CompatibilityN/A
20Build Infrastructure & DependenciesN/A
21Scope & PR Discipline✅ LGTM
22PowerShell Scripting HygieneN/A

15/15 applicable dimensions clean. 2 NIT-level findings (no blocking or major issues).


Summary

The three new tests correctly target the three distinct guard-logic paths in IgnoreStringMethodReturnValueAnalyzer.AnalyzeExpressionStatement:

TestGuard path exercisedVerified correct?
WhenDiscardAssignmentIgnoresReturnValue_NoDiagnosticexpressionStatementOperation.Operation is not IInvocationOperation — the outer operation is ISimpleAssignmentOperation (a discard), so early return fires; no diagnostic
WhenStringMethodReturnValueIgnoredInsideLambda_DiagnosticBlock-body lambda still emits an IExpressionStatementOperation; analyzer fires correctly inside the lambda
WhenStringMethodResultUsedAsReceiverForChainedCall_NoDiagnosticOuter IInvocationOperation is GetHashCode() on System.Boolean, not a string method; IsStringMethodCall returns false

All tests are properly isolated (no shared mutable state, no file system operations), non-flaky, and follow the project's CSharpCodeFixVerifier pattern. The using System; directive is correctly included only where System.Action is needed (the lambda test). No expression-bodied lambda gap exists because () => str.Contains(...) assigned to Action would not compile — the block-body form is the only valid pattern here.

Two NIT-level findings are attached as inline comments (naming precision on line 161, comment precision on line 170). Neither affects correctness or reviewer confidence in the PR.

…n comment
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink

Copy link
Copy Markdown
MemberAuthor

🧪 Test quality grade — PR #9468

3 new test methods graded across 1 file (IgnoreStringMethodReturnValueAnalyzerTests.cs). All three tests earn top marks: they follow a clear Arrange/Act+Assert structure, use VerifyCS.VerifyAnalyzerAsync with and without diagnostic markers to assert both positive and negative analyzer behavior, and carry descriptive names that communicate the scenario and expected outcome. No improvements are needed.

ΔTestGradeBandNotes
newIgnoreStringMethodReturnValueAnalyzerTests.
WhenExplicitDiscardAssignment_
NoDiagnostic
A90–100Clear AAA; verifies the discard-assignment early-return guard produces no false positives.
newIgnoreStringMethodReturnValueAnalyzerTests.
WhenStringMethodResultUsedAsReceiverForChainedCall_
NoDiagnostic
A90–100No issues found.
newIgnoreStringMethodReturnValueAnalyzerTests.
WhenStringMethodReturnValueIgnoredInsideLambda_
Diagnostic
A90–100No issues found.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Grade Tests on PR (on open / sync) workflow. · 179 AIC · ⌖ 14.2 AIC · ⊞ 45.7K · [◷]( · )

@Evangelink
Amaury Levé (Evangelink) merged commit eb43ddf into mainJun 28, 2026
42 of 46 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the test-assist/ignore-string-method-edge-cases-1782516482-fa3ee30ff0b2f876 branch June 28, 2026 20:33
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-reviewAwaiting review from the team.type/automationCreated or maintained by an agentic workflow.type/test-gapMissing or insufficient tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Evangelink@0101