@@ -36,6 +36,7 @@ $ cd adder
36
36
これが ` src/lib.rs ` の内容です。
37
37
38
38
``` rust
39
+ # fn main () {}
39
40
#[test]
40
41
fn it_works () {
41
42
}
@@ -102,6 +103,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
102
103
テストを失敗させましょう。
103
104
104
105
``` rust
106
+ # fn main () {}
105
107
#[test]
106
108
fn it_works () {
107
109
assert! (false );
@@ -183,6 +185,7 @@ Windowsでは、 `cmd` を使っていればこうです。
183
185
もう1つのアトリビュート、 ` should_panic ` を使ってテストの失敗を反転させることができます。
184
186
185
187
``` rust
188
+ # fn main () {}
186
189
#[test]
187
190
#[should_panic]
188
191
fn it_works () {
@@ -216,6 +219,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
216
219
Rustはもう1つのマクロ、 ` assert_eq! ` を提供しています。これは2つの引数の等価性を調べます。
217
220
218
221
``` rust
222
+ # fn main () {}
219
223
#[test]
220
224
#[should_panic]
221
225
fn it_works () {
@@ -256,6 +260,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
256
260
前述の例のもっと安全なバージョンはこうなります。
257
261
258
262
``` rust
263
+ # fn main () {}
259
264
#[test]
260
265
#[should_panic(expected = " assertion failed" )]
261
266
fn it_works () {
@@ -268,6 +273,7 @@ fn it_works() {
268
273
「リアルな」テストを書いてみましょう。
269
274
270
275
``` rust,ignore
276
+ # fn main() {}
271
277
pub fn add_two(a: i32) -> i32 {
272
278
a + 2
273
279
}
@@ -291,6 +297,7 @@ fn it_works() {
291
297
そのようなテストは、 ` ignore ` アトリビュートを使ってデフォルトでは無効にすることができます。
292
298
293
299
``` rust
300
+ # fn main () {}
294
301
#[test]
295
302
fn it_works () {
296
303
assert_eq! (4 , add_two (2 ));
@@ -360,6 +367,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
360
367
今までの例の慣用的な書き方はこのようになります。
361
368
362
369
``` rust,ignore
370
+ # fn main() {}
363
371
pub fn add_two(a: i32) -> i32 {
364
372
a + 2
365
373
}
@@ -397,6 +405,7 @@ mod tests {
397
405
` src/lib.rs ` をグロブを使うように変更しましょう。
398
406
399
407
``` rust,ignore
408
+ # fn main() {}
400
409
pub fn add_two(a: i32) -> i32 {
401
410
a + 2
402
411
}
@@ -438,11 +447,11 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
438
447
動きます!
439
448
440
449
<!-- The current convention is to use the `tests` module to hold your "unit-style"-->
441
- <!-- tests. Anything that just tests one small bit of functionality makes sense to-->
450
+ <!-- tests. Anything that tests one small bit of functionality makes sense to-->
442
451
<!-- go here. But what about "integration-style" tests instead? For that, we have-->
443
452
<!-- the `tests` directory.-->
444
453
現在の慣習では、 ` tests ` モジュールは「ユニット」テストを入れるために使うことになっています。
445
- 単一の小さな機能の単位をテストするだけのものは全て 、ここに入れる意味があります。
454
+ 単一の小さな機能の単位をテストするものは全て 、ここに入れる意味があります。
446
455
しかし、「結合」テストはどうでしょうか。
447
456
結合テストのためには、 ` tests ` ディレクトリがあります。
448
457
@@ -456,6 +465,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
456
465
``` rust,ignore
457
466
extern crate adder;
458
467
468
+ # fn main() {}
459
469
#[test]
460
470
fn it_works() {
461
471
assert_eq!(4, adder::add_two(2));
@@ -525,6 +535,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
525
535
これが例を付けた具体的な ` src/lib.rs ` です。
526
536
527
537
``` rust,ignore
538
+ # fn main() {}
528
539
# //! The `adder` crate provides functions that add numbers to other numbers.
529
540
//! `adder`クレートはある数値を数値に加える関数を提供する
530
541
//!
@@ -605,12 +616,7 @@ test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured
605
616
例を追加するにつれて、それらの名前は ` add_two_1 ` というような形で数値が増えていきます。
606
617
607
618
<!-- We haven’t covered all of the details with writing documentation tests. For more,-->
608
- <!-- please see the [Documentation chapter](documentation.html)-->
619
+ <!-- please see the [Documentation chapter](documentation.html). -->
609
620
まだドキュメンテーションテストの書き方の詳細について、全てをカバーしてはいません。
610
621
詳しくは [ ドキュメントの章] ( documentation.html ) を見てください。
611
622
612
- <!-- One final note: documentation tests *cannot* be run on binary crates.-->
613
- <!-- To see more on file arrangement see the [Crates and-->
614
- <!-- Modules](crates-and-modules.html) section.-->
615
- 最後の注意:バイナリクレート上のテストは実行 * できません* 。
616
- ファイルの配置についてもっと知りたい場合は [ クレートとモジュール] ( crates-and-modules.html ) セクションを見ましょう。
0 commit comments