-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow running just unit or integration tests in cargo test #10491
Comments
There is:
There is this though it requires some more work to get the behavior you are looking for
Though if you switch to one or only a couple of test targets like matklad talks about, it will improve link times in your CI and make it easier to reference your black box tests.
imo Splitting on just unit vs integration test is only a stop gap measure for helping with the problem of CI times. A lot of smaller crates won't be helped because test times will be so small that CI jobs will all be compilation time and by splitting it up into multiple jobs, users will just hit their max concurrent runner cap, serializing their CI jobs and slowing down their overall CI. For users with larger test sets and "unlimited" number of concurrent runners, the solutions I tend to see outside of Rust that would be good starting points to look to are:
|
What if I have a binary with unit tests? Re. the rest of your response, I see what you mean and I'll think about applying some of these things to the projects I work on. I still feel like having these sorts of flags could be nice though – in particular in workspace crates where test output is often long, it would be beneficial to go over smaller sets of tests locally and re-run just those (with fewer stuff to rebuild) when something fails. If that doesn't convince you though, feel free to just close this issue. If it seems unlikely this would be implemented I can live with that. |
|
I should state that internally Cargo doesn't have the concept of unit/integration tests. All it does is to invoke Since you've mentioned doctests, the behaviour is quite different from other kinds of tests. Here is a related comment3 from me you might be interested in. The Cargo book haven't yet covered it well, but yeah, doc improvements are always welcome! BTW, it could help more if you can provide a concrete example for your use case. Footnotes |
Just to be clear, this can be done today:
|
I guess there's really no point in keeping this open then. There seem to be some related improvements to be had, but I'm no longer convinced having more (dedicated) flags for these things would be an improvement. |
Problem
cargo test
has a flag for running just doctests (--doc
) but equivalent flags for running just unit tests (compiling the crate withcfg(test)
but not compiling integration tests) or integration tests (compiling the crate withoutcfg(test)
but compiling and running integration tests don't seem to be available.This would be useful for improving CI times for crates with many tests, as you could run these two things in separate CI jobs and parallelize them that way.
Proposed Solution
Add
--unit-tests
and--integration-tests
flags, or some equivalent.The text was updated successfully, but these errors were encountered: