dotnet-testofficial

assertion-quality

dotnet/skills · updated May 23, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/dotnet/skills --skill assertion-quality
0 commentsdiscussion
summary

Analyzes the variety and depth of assertions across .NET test suites. Use when the user asks to evaluate assertion quality, find shallow testing, identify assertion-free tests (no assertions or only trivial ones like Assert.IsNotNull), flag self-referential or tautological assertions (output equals input on identity/round-trip operations), measure assertion coverage diversity, or audit whether tests verify different facets of correctness. Produces metrics and actionable recommendations. Works with MSTest, xUnit, NUnit, TUnit. DO NOT USE FOR: writing new tests (use writing-mstest-tests), other anti-patterns like flakiness or duplication (use test-anti-patterns), or fixing assertions.

skill.md
name
assertion-quality
description
"Analyzes the variety and depth of assertions across .NET test suites. Use when the user asks to evaluate assertion quality, find shallow testing, identify assertion-free tests (no assertions or only trivial ones like Assert.IsNotNull), flag self-referential or tautological assertions (output equals input on identity/round-trip operations), measure assertion coverage diversity, or audit whether tests verify different facets of correctness. Produces metrics and actionable recommendations. Works with MSTest, xUnit, NUnit, TUnit. DO NOT USE FOR: writing new tests (use writing-mstest-tests), other anti-patterns like flakiness or duplication (use test-anti-patterns), or fixing assertions."
license
MIT

Assertion Diversity Analysis

Analyze .NET test code to measure how varied and meaningful the assertions are. Produce a metrics report that reveals whether tests verify different facets of correctness — not just "output equals X" but also structure, exceptions, state transitions, side effects, and invariants.

Why Assertion Diversity Matters

Low assertion diversity signals shallow testing. Tests may pass while bugs hide in unasserted logic. Common symptoms:

ProblemSymptomConsequence
Trivial assertionsAssert.IsNotNull(result) onlyTest passes but doesn't verify correctness
Single-value obsessionAlways check one field or return valueBugs in unasserted logic slip through
No negative assertionsNever check what shouldn't happenRegressions sneak in through false positives
No state checksDon't verify object state changesMissed side-effects or lifecycle issues
No structural checksOnly assert top-level valueBugs in nested objects go unnoticed
Assertion-free testsTests that call but don't verifyCode coverage lies; false security

When to Use

  • User asks to evaluate assertion quality or depth
  • User asks "are my tests actually testing anything meaningful?"
  • User wants to know if test assertions are too shallow or trivial
  • User asks for assertion coverage metrics or diversity analysis
  • User suspects tests give false confidence despite passing

When Not to Use

  • User wants to write new tests (use writing-mstest-tests)
  • User wants to detect anti-patterns beyond assertions (use test-anti-patterns)
  • User wants to fix or rewrite assertions (help them directly)
  • User asks about code coverage percentages (out of scope — this analyzes assertion quality, not line coverage)

Inputs

InputRequiredDescription
Test codeYesOne or more test files or a test project directory to analyze
Production codeNoThe code under test, to evaluate whether assertions cover the important behaviors

Workflow

Step 1: Gather the test code

Read all test files the user provides. If the user points to a directory or project, scan for all test files — see the dotnet-test-frameworks skill for framework-specific markers.

Step 2: Classify every assertion

For each test method, identify all assertions and classify them into these categories:

CategoryExamplesWhat it verifies
EqualityAssert.AreEqual, Assert.Equal, Is.EqualToReturn value matches expected
BooleanAssert.IsTrue, Assert.IsFalse, Assert.TrueCondition holds
Null checksAssert.IsNull, Assert.IsNotNull, Assert.NotNullPresence/absence of value
ExceptionAssert.ThrowsException, Assert.Throws, Assert.ThrowsAsyncError handling behavior
Type checksAssert.IsInstanceOfType, Assert.IsAssignableFromRuntime type correctness
StringStringAssert.Contains, StringAssert.StartsWith, Assert.MatchesText content and format
CollectionCollectionAssert.Contains, Assert.Contains, Assert.All, Has.MemberCollection contents and structure
ComparisonAssert.IsTrue(x > y), Assert.InRange, Is.GreaterThanOrdering and magnitude
ApproximateAssert.AreEqual(expected, actual, delta), Is.EqualTo().Within()Floating-point or tolerance-based
NegativeAssert.AreNotEqual, Assert.DoesNotContain, Assert.DoesNotThrowWhat should NOT happen
State/Side-effectAssertions on object properties after mutation, verifying mock callsState transitions and side effects
Structural/DeepAssertions on nested properties, serialized forms, complex objectsDeep object correctness

A single assertion can belong to multiple categories (e.g., Assert.AreNotEqual is both Equality and Negative).

Step 3: Compute metrics

Calculate these metrics for the test suite:

Per-test metrics

  • Assertion count: Number of assertions in each test method
  • Assertion categories: Which categories each test uses

Suite-wide metrics

  • Average assertions per test: Total assertions / total test methods
  • Assertion type spread: Number of distinct assertion categories used across the suite (out of 12)
  • Tests with zero assertions: Count and percentage of test methods with no assertions at all
  • Tests with only trivial assertions: Count and percentage of tests where every assertion is only a null check or Assert.IsTrue(true) — trivial means no meaningful value verification
  • Tests with self-referential assertions: Count and percentage of tests whose assertions compare an input to a round-tripped or identity-transformed version of itself (e.g., Assert.AreEqual(input, Parse(input.ToString()))) or assert a field against itself (Assert.AreEqual(dto.Name, dto.Name)). These are tautological — they verify the plumbing, not the behavior.
  • Tests with negative assertions: Count and percentage (target: at least 10% of tests should verify what should NOT happen)
  • Tests with exception assertions: Count and percentage
  • Tests with state/side-effect assertions: Count and percentage
  • Tests with structural/deep assertions: Count and percentage
  • Single-category tests: Count and percentage of tests that use only one assertion category

Step 4: Apply calibration rules

Before reporting, calibrate findings:

  • Trivial means truly trivial. Assert.IsNotNull(result) alone is trivial. But Assert.IsNotNull(result) followed by Assert.AreEqual(expected, result.Value) is not — the null check is a guard before the real assertion. Only flag a test as "trivial" if it has no meaningful value assertions.
  • Boolean assertions checking meaningful conditions are not trivial. Assert.IsTrue(result.IsValid) checks a specific property — it's a Boolean assertion, not a trivial one. Assert.IsTrue(true) is trivial.
  • Consider the test's intent. A test for a void method that verifies state change on a dependency is legitimate even if it only uses Assert.IsTrue.
  • Exception tests are inherently low-assertion-count. Assert.ThrowsException<T>(() => ...) may be the only assertion — that's fine for exception-focused tests. Don't penalize them for low assertion count.
  • Don't conflate diversity with volume. A test with 20 Assert.AreEqual calls has high volume but low diversity. A test with one equality, one null check, and one exception assertion has low volume but good diversity.
  • Self-referential assertions are not meaningful equality checks. Assert.AreEqual(input, roundTrip(input)) looks like a real equality assertion but is tautological when the operation under test is expected to be identity. Flag these separately from normal equality assertions. If the test's purpose is to verify a round-trip (serialize/deserialize, encode/decode), the assertion is valid — but it should be accompanied by assertions on non-trivial inputs that exercise the transformation.
  • If assertions are well-diversified, say so. A report concluding the suite has good diversity is perfectly valid.

Step 5: Report findings

Present the analysis in this structure:

  1. Summary Dashboard — A quick-reference table of key metrics:

    | Metric                        | Value  | Assessment |
    |-------------------------------|--------|------------|
    | Total tests                   | 25     | —          |
    | Average assertions per test   | 2.4    | Moderate   |
    | Assertion type spread         | 5/12   | Low        |
    | Tests with zero assertions    | 3 (12%)| Concerning |
    | Tests with only trivial asserts | 4 (16%)| Acceptable |
    | Tests with negative assertions | 2 (8%) | Below target |
    | Single-category tests         | 15 (60%)| High       |
    
  2. Category Breakdown — For each assertion category, show:

    • How many tests use it
    • Representative examples from the code
    • Whether it's overused or underused relative to the code under test
  3. Gap Analysis — Based on the production code (if available), identify:

    • Behaviors that are tested but only with equality checks
    • Error paths with no exception assertions
    • State-changing methods with no state verification
    • Collections returned but never checked for contents
  4. Recommendations — Prioritized list of improvements:

    • Which tests would benefit most from additional assertion types
    • Which assertion categories are missing and why they matter
    • Concrete examples of assertions that could be added
  5. Assertion-free tests — If any exist, list each one with its method name and what it appears to be testing, so the user can decide whether to add assertions or mark them as intentional smoke tests.

Validation

  • Every assertion in the test suite was classified into at least one category
  • Metrics are computed correctly (counts add up)
  • Trivial-assertion tests are correctly identified (not over-flagged)
  • Exception tests are not penalized for low assertion count
  • Boolean assertions on meaningful properties are not classified as trivial
  • Recommendations are concrete (name specific test methods and suggest specific assertion types)
  • If the suite has good diversity, the report acknowledges this

Common Pitfalls

PitfallSolution
Penalizing exception tests for low assertion countException assertions are complete on their own — skip count warnings for these
Flagging null checks before value checks as trivialOnly flag tests where the null check is the ONLY assertion
Counting Assert.IsTrue(condition) as trivialOnly Assert.IsTrue(true) or always-true conditions are trivial
Ignoring framework differencesMSTest uses Assert.AreEqual, xUnit uses Assert.Equal, NUnit uses Is.EqualTo — classify all correctly
Recommending diversity for diversity's sakeOnly suggest adding assertion types that would catch real bugs in the code under test
Missing implicit assertionsAssert.ThrowsException is both an exception assertion and a negative assertion (verifying that calling the method has a specific failure mode)
how to use assertion-quality

How to use assertion-quality on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add assertion-quality
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/dotnet/skills --skill assertion-quality

The skills CLI fetches assertion-quality from GitHub repository dotnet/skills and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/assertion-quality

Reload or restart Cursor to activate assertion-quality. Access the skill through slash commands (e.g., /assertion-quality) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.628 reviews
  • Diego Ndlovu· Dec 20, 2024

    I recommend assertion-quality for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Sakura Martin· Dec 16, 2024

    assertion-quality reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Dhruvi Jain· Dec 12, 2024

    assertion-quality has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Diego Park· Nov 11, 2024

    Useful defaults in assertion-quality — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Oshnikdeep· Nov 3, 2024

    Keeps context tight: assertion-quality is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Ganesh Mohane· Oct 22, 2024

    We added assertion-quality from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Evelyn Yang· Oct 2, 2024

    Registry listing for assertion-quality matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Hiroshi White· Sep 21, 2024

    Keeps context tight: assertion-quality is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Liam Taylor· Sep 9, 2024

    We added assertion-quality from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Sakshi Patil· Sep 1, 2024

    Useful defaults in assertion-quality — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

showing 1-10 of 28

1 / 3