File tree Expand file tree Collapse file tree
listings/ch11-writing-automated-tests
no-listing-01-changing-test-name/src
no-listing-10-result-in-tests/src
no-listing-11-ignore-a-test/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- pub fn add ( left : usize , right : usize ) -> usize {
1+ pub fn add ( left : u64 , right : u64 ) -> u64 {
22 left + right
33}
44
Original file line number Diff line number Diff line change 1- pub fn add ( left : usize , right : usize ) -> usize {
1+ pub fn add ( left : u64 , right : u64 ) -> u64 {
22 left + right
33}
44
Original file line number Diff line number Diff line change 1- pub fn add ( left : usize , right : usize ) -> usize {
1+ pub fn add ( left : u64 , right : u64 ) -> u64 {
22 left + right
33}
44
Original file line number Diff line number Diff line change 1- pub fn add ( left : usize , right : usize ) -> usize {
1+ pub fn add ( left : u64 , right : u64 ) -> u64 {
22 left + right
33}
44
Original file line number Diff line number Diff line change @@ -62,16 +62,19 @@ cd ../../..
6262
6363</Listing >
6464
65+ The file starts with an example ` add ` function, so that we have something
66+ to test.
67+
6568For now, let’s focus solely on the ` it_works ` function. Note the ` #[test] `
6669annotation: this attribute indicates this is a test function, so the test
6770runner knows to treat this function as a test. We might also have non-test
6871functions in the ` tests ` module to help set up common scenarios or perform
6972common operations, so we always need to indicate which functions are tests.
7073
7174The example function body uses the ` assert_eq! ` macro to assert that ` result ` ,
72- which contains the result of adding 2 and 2, equals 4. This assertion serves as
73- an example of the format for a typical test. Let’s run it to see that this test
74- passes.
75+ which contains the result of calling ` add ` with 2 and 2, equals 4. This
76+ assertion serves as an example of the format for a typical test. Let’s run it
77+ to see that this test passes.
7578
7679The ` cargo test ` command runs all tests in our project, as shown in Listing
778011-2.
You can’t perform that action at this time.
0 commit comments