# Enable futures in \[profile.test\]

**URL:** <https://internals.rust-lang.org/t/enable-futures-in-profile-test/18620>\
**Category:** cargo\
**Created:** [April 4, 2023, 7:44am UTC](https://internals.rust-lang.org/t/enable-futures-in-profile-test/18620 "2023-04-04T07:44:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![silence-coding](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/silence-coding/32/8025_2.png) [@silence-coding](https://internals.rust-lang.org/u/silence-coding)\
**Post date:** [April 4, 2023, 7:44am UTC](https://internals.rust-lang.org/t/enable-futures-in-profile-test/18620/1 "2023-04-04T07:44:25Z")

</div>

Can cargo test enable crate to directly enble some features?

```rust
[profile.test]
required-features = ["for-test"]

```

> **[How to reference the test of another crate in the current crate](https://users.rust-lang.org/t/how-to-reference-the-test-of-another-crate-in-the-current-crate/91965)**
>
> I expect to reference A's test tool code in B, but that doesn't seem to work, and the test tag won't be passed to A crate when cargo test is performed. crate a: #\[cfg!(test)\] pub mod test\_utils { use std::path::PathBuf; pub fn...

---

<div class="post-metadata">

**Author:** ![ehuss](https://avatars.discourse-cdn.com/v4/letter/e/9de0a6/32.png) [@ehuss](https://internals.rust-lang.org/u/ehuss)\
**Post date:** [April 4, 2023, 2:12pm UTC](https://internals.rust-lang.org/t/enable-futures-in-profile-test/18620/2 "2023-04-04T14:12:56Z")

</div>

If you want to enable the feature of a dependency while testing, you can place the feature in the `dev-dependencies` table, like this:

```rust
[dependencies]
some-dependency = { path = "some-dependency" }

[dev-dependencies]
some-dependency = { path = "some-dependency", features = ["for-test"] }

```

I don't recommend doing this. I would suggest restructuring your crates so that test-specific needs are in a separate crate. When running tests, it is best for the code being tested to be the same as the non-test scenario.

For questions on how to use Cargo, I suggest using [https://users.rust-lang.org/](https://users.rust-lang.org/). This forum is for the discussion of the development of Rust itself.

---

<div class="post-metadata">

**Author:** ![silence-coding](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/silence-coding/32/8025_2.png) [@silence-coding](https://internals.rust-lang.org/u/silence-coding)\
**Post date:** [April 6, 2023, 10:25am UTC](https://internals.rust-lang.org/t/enable-futures-in-profile-test/18620/3 "2023-04-06T10:25:26Z")

</div>

> [@silence-coding](#):
>
> `profile`

I'm not talking about the use of cargo, the purpose of this is to discuss whether features can be enabled in profiles. You're right, we should try to make sure that we're testing the same code, but now there's a scenario where I want to provide testing features in crate, like not starting the actual backend dependency, but a stub. (Rust doesn't have tools like [GitHub - mockito/mockito: Most popular Mocking framework for unit tests written in Java](https://github.com/mockito/mockito), and mockall doesn't meet my needs well.)

---

<div class="post-metadata">

**Author:** ![silence-coding](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/silence-coding/32/8025_2.png) [@silence-coding](https://internals.rust-lang.org/u/silence-coding)\
**Post date:** [April 6, 2023, 10:31am UTC](https://internals.rust-lang.org/t/enable-futures-in-profile-test/18620/4 "2023-04-06T10:31:48Z")

</div>

@ehuss Usage issues I discussed earlier at [https://users.rust-lang.org/](https://users.rust-lang.org/)[How to reference the test of another crate in the current crate - #2 by silence-coding - help - The Rust Programming Language Forum](https://users.rust-lang.org/t/how-to-reference-the-test-of-another-crate-in-the-current-crate/91965/2)

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [December 22, 2024, 5:26pm UTC](https://internals.rust-lang.org/t/enable-futures-in-profile-test/18620/5 "2024-12-22T17:26:08Z")

</div>

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
