Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Provide a way to run unit tests in random order #1942

Open
IndrajeetPatil opened this issue Mar 10, 2024 · 1 comment
Open

FR: Provide a way to run unit tests in random order #1942

IndrajeetPatil opened this issue Mar 10, 2024 · 1 comment
Labels
feature a feature request or enhancement tests 📘

Comments

@IndrajeetPatil
Copy link

Preamble

Running unit tests in random order can help uncover hidden dependencies and assumptions within the tests themselves. When tests are run in a predetermined order, it's possible for dependencies between tests or shared state to go unnoticed. Randomizing the order can expose these issues, ensuring that each test is truly independent and capable of standing on its own.

In Python pytest-random-order plugin for pytest provides this functionality.

Feature request

Currently, {testthat} always runs tests in the alphabetical order (except when Config/testthat/start-first is set), and it would be great if it can also provide a way to run the tests in randomized order to detect coupling between different tests.

Not sure about the possible API: It could either be a new function or a parameter to test_dir(), which is then exposed via devtools::test().

@hadley hadley added feature a feature request or enhancement tests 📘 labels Apr 17, 2024
@hadley
Copy link
Member

hadley commented Apr 17, 2024

Hmmm, interesting idea, and it would be easy enough to implement by calling sample() on the parsed vector.

To me feels like it would be best exposed as an argument to devtools::test().

...

Oh are you thinking random file order, or random order within file, or both?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement tests 📘
Projects
None yet
Development

No branches or pull requests

2 participants