Curriculum Errors, crates & tests Cargo and testing
Cargo and testing
Cargo is Rust's build tool, package manager, test runner, and project skeleton. This theme teaches Cargo.toml, crates, binaries vs libraries, unit tests, integration tests, and assert_eq!. Planned exercises: 1. choose the purpose of Cargo.toml. 2. recognise crate roots. 3. choose #[test]. 4. fill assert_eq!. 5. fill a module test path. 6. write a unit test. 7. write a result-returning test. 8. translate a TS test into Rust assertions. 9. organise a tiny library and binary split.
Exercises
9 ready
01
pick one
A new Rust project ships a Cargo.toml. Pick the statement
02
pick one
A Cargo project has BOTH a binary and a library inside the
03
pick one
Pick the attribute that marks a function as a UNIT TEST
04
fill blanks
Fill the assertion MACRO that checks two values are equal and
05
type one line
Inside a #[cfg(test)] mod tests block, write the line that
06
write a program
Write a single Rust file with: an add(a: i32, b: i32) -> i32
07
write a program
Tests can return Result<(), E> to use ? for fallible
08
write a program
Translate the Vitest/Jest test to Rust. Production function
09
write a program
A real Cargo project would have src/lib.rs exposing the