Skip to content

[Test Improver] Add unit tests for CommandLineOption #8310

@Evangelink

Description

@Evangelink

🤖 Test Improver — automated AI assistant

Goal and Rationale

CommandLineOption is a public API class with non-trivial validation logic in its constructor: it validates name/description for null/whitespace, enforces arity constraints (Max ≥ Min), and rejects names with characters outside [a-zA-Z0-9-?]. It also implements IEquatable<CommandLineOption> with a custom GetHashCode. Despite being a fundamental building block for all CLI extension authors, it had no dedicated unit tests.

Approach

Added CommandLineOptionTests.cs with 26 test cases (52 total across net8.0 + net9.0) covering:

Category Tests
Valid construction Properties set correctly, IsHidden set correctly
null name/description ArgumentNullException thrown
Empty/whitespace name/description ArgumentException thrown
Invalid arity (Max < Min) ArgumentException thrown
Name with invalid characters (!, @, space, etc.) ArgumentException thrown via [DataRow]
Name with valid characters (opt, my-option, ?, etc.) No exception, name preserved
Equals — matching values true (typed + object overloads)
Equals — differing name/description/arity/isHidden false
Equals — null false
GetHashCode — same values Same hash
GetHashCode — different values Different hash

Test Status

✅ All 52 test executions pass (26 tests × net8.0 + net9.0)

Test run summary: Passed!
  total: 52  failed: 0  succeeded: 52  skipped: 0

Reproducibility

dotnet test test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj \
  -c Debug --filter "CommandLineOptionTests"

Generated by Daily Test Improver · ● 16.2M ·


Note

This was originally intended as a pull request, but the git push operation failed.

Workflow Run: View run details and download bundle artifact

The bundle file is available in the agent artifact in the workflow run linked above.

To create a pull request with the changes:

# Download the artifact from the workflow run
gh run download 26018812150 -n agent -D /tmp/agent-26018812150

# Fetch the bundle into a local branch
git fetch /tmp/agent-26018812150/aw-test-assist-command-line-option-tests.bundle refs/heads/test-assist/command-line-option-tests:refs/heads/test-assist/command-line-option-tests-287cfe29f0af8b9e
git checkout test-assist/command-line-option-tests-287cfe29f0af8b9e

# Push the branch to origin
git push origin test-assist/command-line-option-tests-287cfe29f0af8b9e

# Create the pull request
gh pr create --title '[Test Improver] Add unit tests for CommandLineOption' --base main --head test-assist/command-line-option-tests-287cfe29f0af8b9e --repo microsoft/testfx

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/agentic-workflowsGitHub agentic workflow definitions under .github/workflows/*.md.type/automationCreated or maintained by an agentic workflow.type/test-gapMissing or insufficient tests.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions