Skip to content

Commit ae33acb

Browse files
committed
edit slides
1 parent 40fe008 commit ae33acb

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

slides/11-writing_automated_tests.qmd

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ title: "11. Writing Automated Tests"
1818

1919
## Testing in Rust
2020

21-
- Ensures code functions as expected
22-
- Rust provides support for writing automated tests
23-
- Types of tests in Rust:
21+
- Tests ensure code functions as expected
22+
- Rust (`cargo`) provides native support for automating tests
23+
- Types of test in Rust include:
2424

2525
::: nonincremental
2626
- Unit tests
2727
- Integration tests
28+
- Documentation tests
29+
- Benchmarks
2830
:::
2931

3032
::: notes
@@ -33,6 +35,11 @@ In this chapter, we'll explore how to write tests in Rust to ensure our code wor
3335

3436
# How to Write Tests
3537

38+
## Typical Flow of a Test
39+
- Set up any needed data or state.
40+
- Run the code you want to test.
41+
- Assert that the results are what you expect.
42+
3643
## Anatomy of a Test Function
3744

3845
- Annotate functions with `#[test]` to make them tests
@@ -244,6 +251,7 @@ Ignored tests can be useful for tests that take a long time or require special s
244251
### The Tests Module and `#[cfg(test)]`
245252

246253
- Place tests in a `tests` module annotated with `#[cfg(test)]`
254+
- This module is only compiled when testing
247255

248256
```rust
249257
#[cfg(test)]
@@ -261,7 +269,7 @@ Ignored tests can be useful for tests that take a long time or require special s
261269
The `#[cfg(test)]` attribute ensures the tests are only compiled and run when testing.
262270
:::
263271

264-
### Testing Private Functions
272+
## Testing Private Functions
265273

266274
- You can test private functions in Rust
267275
- Example:
@@ -290,10 +298,7 @@ Because the tests module is inside the same file, it has access to private funct
290298

291299
- Test the public API as an external user would
292300
- Placed in the `tests` directory
293-
294-
### The `tests` Directory
295-
296-
- Create a `tests` directory at the project root
301+
- Each file in `tests` is a separate crate
297302

298303
```
299304
my_project
@@ -303,8 +308,6 @@ Because the tests module is inside the same file, it has access to private funct
303308
└── tests
304309
└── integration_test.rs
305310
```
306-
307-
- Each file in `tests` is a separate crate
308311
- Example:
309312

310313
```rust
@@ -320,7 +323,7 @@ Because the tests module is inside the same file, it has access to private funct
320323
Integration tests verify that your library works as expected when used by others.
321324
:::
322325

323-
### Submodules in Integration Tests
326+
## Submodules in Integration Tests
324327

325328
- Share code between integration tests using modules
326329
- Create `tests/common/mod.rs` for shared code
@@ -345,7 +348,7 @@ Integration tests verify that your library works as expected when used by others
345348
This avoids code duplication in your tests.
346349
:::
347350

348-
### Integration Tests for Binary Crates
351+
## Integration Tests for Binary Crates
349352

350353
- Binary crates (with only `main.rs`) can't be tested directly via integration tests
351354
- Solution: Extract logic into a library crate (`lib.rs`)

0 commit comments

Comments
 (0)