Skip to content

cargo test should show test execution time for slower tests #10208

@nyurik

Description

@nyurik

Problem

cargo test only prints ok/FAILED after each test. In some cases, it might be very useful to see the test duration, similar to mocha-js. Of course this is not as good as having a comprehensive benchmark tests, but in many cases it would give general feedback of how long each test took.

Proposed Solution

Print the time each test took to run in ms, either always, or just for the tests that take longer than some magic number like 10ms:

running 2 tests
test tests::test_fast ... ok
test tests::test_slow ... ok (1200ms)

Notes

Not sure if it would be worth it to introduce attributes to set the expected execution time, something like #[test(slow = 5000)] -- this would clearly be a far wider discussion.

Example from the Mocha project

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions