Skip to content

Show slowest tests #3495

Closed
Closed

Description

Summary

Allow to display slowest tests for a given assembly.

Background and Motivation

On our internal test runs we have an option to display slowest tests. I think this would be a useful feature to provide to users.

Proposed Feature

Add a --show-slowest or --show-slowest-test option.

Activity

  1. added
    area/mtp
    and removed
    needs/triage
    on Aug 8, 2024
  2. Evangelink commented on Aug 8, 2024

    @Evangelink
    MemberAuthor

    To de defined: should this be a core feature or an extension feature?

    I think that because this is not linked to any external deps/service this could be a built-in feature but we could think about having it directly as some external package it we are planning to connect it to some service (AzDO?).
    Marco Rossignoli (@MarcoRossignoli) if I am not mistaken, nothing prevents us (technically) to have this feature as core (built-in) feature and to potentially have some extensions that would enrich this feature (e.g. connection to some history service), right?

  3. MarcoRossignoli commented on Aug 8, 2024

    @MarcoRossignoli
    Contributor

    I would personally do not add "questionable" service built-in. UX falls already in that bucket but we need to show something and we're giving our taste.
    I would keep as an extension.

    Slowest test is also a not well defined concept. Hypothetical fixture system, init feature etc...are affecting the concept of slowest? If my custom adapter group by "group of tests with a category" and I want to measure that group? Some other esoteric framework could implement different concept regarding timing, personally I would not add in the core lib but in an extension where we ship "our" idea of slowest.

  4. Youssef1313 commented on Jan 20, 2026

    @Youssef1313
    Member

    When implementing this, we should also consider how we want dotnet test to behave.

    Should dotnet test re-implement this feature in a way that considers all test projects and show the slowest test for the whole test session? Or should this be a per-testapp feature.

    This question generally keeps popping up for various features.

  5. added
    area/mtp-extensions
    on Jan 20, 2026
  6. Evangelink commented on Jun 15, 2026

    @Evangelink
    MemberAuthor

    Adding a thought from a recent design discussion (#9125, #9139, #9140) — a related angle worth capturing on this issue.

    A different framing: declared expected duration

    Instead of "platform calculates which tests are slowest" (relative, list-based — the original framing of this issue), what if:

    Each test declares its expected duration (or expected range); the platform surfaces a warning when actual > declared.

    That's a declarative twin of #9140's history-driven threshold — same emission point, different input source. Author knows this integration test should complete in under 2s; CI, IDE, and reporters all surface a warning when it doesn't.

    Three architectural options

    Approach Cost Trade-off
    a Pure extension. Each framework ships its own attribute (e.g. [ExpectedDuration(2000)] on MSTest, equivalent on xUnit/NUnit). An extension reads it, compares, warns via the IProgressEnricher hook (#9139). Zero MTP changes. N frameworks → N attribute conventions → N extensions. Reporters can't act uniformly without per-framework knowledge.
    b Platform contract. MTP defines a standard test-node metadata key (expected.duration.max etc.); framework bridges populate it from whatever attribute the framework chooses; platform emits a SlowExpectedTest event when exceeded. Public API addition + buy-in from adapter authors. One standard surface; reporters and extensions act uniformly.
    c Hybrid. Platform exposes the metadata key + warning event; frameworks may populate it; UI/log emission is delegated to extensions/reporters. Modest. Probably the right balance with Marco's earlier don't put taste in core guidance on this very issue.

    The "what state?" question — recommend not introducing a new TestOutcome

    A slow-but-correct test passed its assertions. Marking it failed:

    • Breaks the meaning of fail — green/red CI signal becomes ambiguous (people chase non-bugs).
    • Maps awkwardly into TRX/JUnit XML — no PassedWithWarning state exists in those formats; they'd round to pass anyway.
    • Conflicts mentally with the hard-timeout semantics frameworks already have ([Fact(Timeout = 1000)], MSTest [Timeout], NUnit [Timeout] all FAIL the test when exceeded).

    Recommended principle: outcome stays Passed; the warning rides on a separate annotation channel on the result. Reporters render yellow/orange; CI extensions emit ::warning:: (GitHub) or ##vso[task.logissue type=warning] (AzDO); IDEs can surface a slow tests filter. Test still counts as passing in counts and exit codes.

    If a user genuinely wants hard failure on slow tests, the existing Timeout attributes already do that.

    Coexistence with existing Timeout

    Two distinct concepts that can coexist on the same test:

    Concept Behaviour Existing API
    Hard timeout Abort the test, mark Failed [Fact(Timeout)], MSTest [Timeout], NUnit [Timeout]
    Expected duration (soft) Let the test finish, mark Passed, attach a warning new — this issue

    Example intent: [ExpectedDuration(2_000)] [Timeout(10_000)] → "I expect this in ≤2s, kill it at 10s."

    Is there a point at all in having this on MTP side?

    The blunt answer: only if we choose (b) or (c).

    If we choose (a), it's purely a framework-by-framework story and MTP should stay out of it (which is consistent with Marco Rossignoli (@MarcoRossignoli)'s earlier comment on this issue).

    Open questions

    1. (a), (b), or (c)? Leaning (c) personally — keeps core lean while making the data uniform.
    2. Single max only, or full min/target/max range? Range adds unexpectedly fast detection (regression-the-other-way), but more API surface.
    3. Per data row or per method for parameterised tests?
    4. Should the same channel accept both absolute (2s) and relative (3× historical p99, from Azure DevOps history-driven slow-test threshold enricher #9140) declarations, so reporters have one thing to render?

    Related design context: #9125 (umbrella for progress reporting), #9139 (IProgressEnricher hook surface this would plug into), #9140 (history-driven threshold — the dynamic twin of this declarative proposal).

  7. github-actions commented on Jul 30, 2026

    @github-actions
    Contributor

    Bringing an energy-efficiency lens to this design discussion.

    Why "slowest tests" matters for energy

    From a Green Software Foundation perspective, every second of unnecessary test-host CPU time translates to joules consumed — across CI machines, developer laptops, and cloud runners. A test that takes 30 s when it should take 3 s burns roughly 10× the energy for that one invocation. Multiply by a typical CI frequency (dozens of runs per day per repo) and the cumulative waste becomes significant.

    The declarative expected duration approach outlined above (option c) maps naturally onto this:

    • It makes energy cost visible — a slow test that regularly exceeds its declared budget shows up in dashboards, giving maintainers actionable data to investigate.
    • It creates a feedback loop without blocking CI — the test still passes, but the warning surfaces the inefficiency without creating noise.

    Energy-efficient implementation considerations

    If a SlowExpectedTest warning path is added, a couple of implementation notes from an efficiency angle:

    1. Avoid per-test allocations in the happy path. The comparison actual > declared should be a simple arithmetic compare on pre-stored integers. If the threshold comes from a custom attribute, cache it at discovery time alongside TestMethodInfo/TestNodeDescriptor rather than re-reading it per invocation.

    2. Emit the warning lazily. If zero tests exceed their threshold (the common case), the warning-construction and routing code should never execute — guard with an early if (elapsed > threshold) before any allocation.

    3. Reporting vs. per-test overhead. The existing SlowTests tracking in the terminal reporter (SimplifiedConsoleOutputDeviceBase.SlowTests.cs) already batches display — the same pattern works here.

    Connecting to SCI

    The [Software Carbon Intensity (SCI)]((sci.greensoftware.foundation/redacted) equation SCI = (E × I + M) / R applies directly to test suites: the functional unit R is "one CI run". Identifying and fixing chronically slow tests reduces E (energy consumed per run), lowering SCI. A platform-level mechanism that surfaces slow tests gives teams the data they need to act.

    Option (c) (platform metadata key + extension rendering) seems like the right call for this reason too — it keeps the measurement instrumentation in one place, making it easy to aggregate SCI-relevant data across frameworks.

    🤖 Automated content by GitHub Copilot. Generated by the Efficiency Improver workflow. · sonnet46 117 AIC · ⌖ 4.19 AIC · ⊞ 14.2K · [◷]( · ◷)

    Add this agentic workflow to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/efficiency-improver.md@main
    
  8. Evangelink commented on Nov 6, 2026

    @Evangelink
    MemberAuthor

    The original per-assembly request is delivered by #9894: --show-slowest-tests <count> lists the slowest completed tests in the run summary. Closing that original scope as completed. The separate opt-in MSTest soft-duration-budget proposal is tracked in #12245; that work preserves existing test outcomes and timeout behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mtparea/mtp-extensions

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions