-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ch 12-4: " Feel free to write some tests...on your own" belies the complexity of doing that #2223
Comments
carols10cents
added a commit
that referenced
this issue
Dec 23, 2021
carols10cents
added a commit
that referenced
this issue
Dec 27, 2021
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jan 4, 2022
Update books ## reference 3 commits in 06f9e61931bcf58b91dfe6c924057e42ce273ee1..f8ba2f12df60ee19b96de24ae5b73af3de8a446b 2021-12-17 07:31:40 -0800 to 2022-01-03 11:02:08 -0800 - Switch the default edition for examples to 2021 (rust-lang/reference#1125) - Clarify behavior of x87 FP registers in inline assembly (rust-lang/reference#1126) - Add inline assembly to the reference (rust-lang/reference#1105) ## book 36 commits in 8a0bb3c96e71927b80fa2286d7a5a5f2547c6aa4..d3740fb7aad0ea4a80ae20f64dee3a8cfc0c5c3c 2021-12-22 20:54:27 -0500 to 2022-01-03 21:46:04 -0500 - Add a concrete example of an optional value. Fixes rust-lang/book#2848. - match isn't really an operator. Fixes rust-lang/book#2859 - Edits to edits of chapter 6 - Make fixes recommended by shellcheck - Use shellcheck - SIGH fix all the typos that were missed while spellcheck was broken - SIGH add all the words to the dictionary that were missed while spellcheck was broken - Remove test_harness from the dictionary - sigh, the xkcd sandwich one - Install aspell in CI - set -eu in all bash scripts - typo: assignement -> assignment - Fix quotes - Snapshot of ch12 for nostarch - Use 'static lifetime earlier because that's more correct. Fixes rust-lang/book#2864. - Add does_not_compile annotation to intermediate steps that don't compile - Sidestep who provides output streams. Fixes rust-lang/book#2933. - Remove note about primitive obsession. Fixes rust-lang/book#2863. - Remove sentence encouraging writing tests on your own. Fixes rust-lang/book#2223. - Bump mdBook version to 0.4.14 in workflow main.yml - Past tense make better sense - Past tense makes better sense - Update the edition in all the listings' Cargo.toml - Update the book to either say 2021 edition or not talk about editions - Remove most of the 2018 edition text from the title page. Fixes rust-lang/book#2852. - Fix word wrapping - Emphasize return type is mandatory - fix title capitalization - Further edits to mention of --include-ignored, propagate to src - feat: mention `cargo test -- --include-ignored` - wording: get rid of "to from" - interchanged position of `binary` and `library` - Fix wrong word typo - Further edits in rust-analyzer text - appendix-04 IDE integration: Replaced rls by rust-analyzer - Update link to Italian translation. Connects to rust-lang/book#2484. ## rustc-dev-guide 3 commits in 9bf0028..8754644 2021-12-20 21:53:57 +0900 to 2021-12-28 22:17:49 -0600 - Update link to moved section (rust-lang/rustc-dev-guide#1282) - Fix link in contributing.md (rust-lang/rustc-dev-guide#1280) - Streamline "Getting Started" (rust-lang/rustc-dev-guide#1279)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure it's a good idea to have the sentence "Feel free to write some tests for the functionality in the Config::new and run functions on your own" be the end of the opening paragraph of Chapter 12-4. The main reason I think that is because of
run
's side effects:Many programmers will instinctively reach for test doubles when unit testing this function in order to isolate it from IO. As I found out, good, versatile test doubles in Rust are quite challenging to set up for a beginner. I eventually arrived at a solution I was happy with, but it took me 10 hours of reading and coding to get there starting from what I had learned so far, with lots of bumps and false starts along the way. Although I feel a lot more comfortable with Rust's advanced features now, and I'm deeply relieved to know that nice test doubles are possible to implement in it, I don't think the book intends for the reader to go to such great lengths at the beginning of this chapter.
It would be nice if Rust either had stronger first-class supporting for testing, or features that make testing easier, like default parameter values and keyword arguments. In either case, readers could then be lightly introduced to idiomatic versions of these sorts of common testing patterns in Chapter 11, enabling them to write unit tests for
run
without much trouble. With the language in its current state, though, that doesn't really seem practical, so I think it might be a good idea to put off discussion of them until readers have gotten more comfortable with traits and generics.I do get that it's a little weird to launch into TDDing a new feature while there's untested code lying around. Maybe the end of the opening paragraph could say something like, "Feel free to write some tests for the functionality in the Config::new and run functions on your own. Don't sweat it if you find it challenging at this point—it'll get easier as you become more familiar with the type system." I think I would have found my initial difficulty with test doubles less disturbing if I had read that.
The text was updated successfully, but these errors were encountered: