1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-25 07:32:40 +02:00
Dustin J. Mitchell 9f67c9b0e7
Adjust morning-session timings downward ()
Based on feedback from @marshallpierce that mornings took about 2.5
hours, this adjusts a bunch of the morning times downward to try to
match that. In other words, this is trying to make the times in the
course more accurate, rather than reducing the amount of time available
for these slides.

This also updates the `course-schedule` tool to be able to show
per-segment timings.
2024-02-06 15:48:56 -05:00

48 lines
1.1 KiB
Markdown

---
minutes: 5
---
# Other Types of Tests
## Integration Tests
If you want to test your library as a client, use an integration test.
Create a `.rs` file under `tests/`:
```rust,ignore
// tests/my_library.rs
use my_library::init;
#[test]
fn test_init() {
assert!(init().is_ok());
}
```
These tests only have access to the public API of your crate.
## Documentation Tests
Rust has built-in support for documentation tests:
````rust
/// Shortens a string to the given length.
///
/// ```
/// # use playground::shorten_string;
/// assert_eq!(shorten_string("Hello World", 5), "Hello");
/// assert_eq!(shorten_string("Hello World", 20), "Hello World");
/// ```
pub fn shorten_string(s: &str, length: usize) -> &str {
&s[..std::cmp::min(length, s.len())]
}
````
- Code blocks in `///` comments are automatically seen as Rust code.
- The code will be compiled and executed as part of `cargo test`.
- Adding `#` in the code will hide it from the docs, but will still compile/run
it.
- Test the above code on the
[Rust Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3ce2ad13ea1302f6572cb15cd96becf0).