#I need help with automated tests in my project

5 messages · Page 1 of 1 (latest)

obsidian igloo
#

Hello!

I'm trying to create automated tests and I've been following the tutorial (From the rust book) and I was able to build and make a the test example.
However, I want to make tests for my project and it's from another cargo file. I want to import my projects function calls in the tests (The automated tests).

NOTE: this cargo.toml below is for the main.rs binary.

Cargo.toml for project:

workspace = { members = ["automated_tests"] }
[package]
name = "terminal_adventure"
version = "0.1.0"
edition = "2021"

# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# NOTE: Remember to revert this before releasing your game! 
# Otherwise you will need to include libbevy_dylib alongside your game if you want it to run. 
# If you remove the "dynamic" feature, your game executable can run standalone.
bevy = { version = "0.12.1", features = ["dynamic_linking"] }
bevy_ascii_terminal = "0.14.0"
bevy_interact_2d = "0.9.0"

NOTE: the cargo.toml below is for the lib.rs

The Cargo.toml for the test:

[package]
name = "automated_tests"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

Any guidance or help would be appreciated.

still pelican
#

You can't test functions from a binary crate using another crate. Pick one of these alternatives:

  • Put the functions you want to test in a library crate (you can add a lib.rs to the terminal_adventure package if you want; you don't necessarily need a new package)
  • Put your #[test] functions inside the terminal_adventure code instead of a separate package.
  • Test your binary by running it, not by calling its functions.
obsidian igloo
marsh yacht
#

nobody does that

#

people just make a mod tests { ... } inside the file where the functions are