cargo test
のコマンド引数。
成果物
cargo test
のコマンド引数
cargo test --help
$ cargo test --help cargo-test Execute all unit and integration tests and build examples of a local package USAGE: cargo test [OPTIONS] [TESTNAME] [-- <args>...] OPTIONS: --lib Test only this package's library unit tests --bin <NAME>... Test only the specified binary --bins Test all binaries --example <NAME>... Test only the specified example --examples Test all examples --test <NAME>... Test only the specified test target --tests Test all tests --bench <NAME>... Test only the specified bench target --benches Test all benches --all-targets Test all targets --doc Test only this library's documentation --no-run Compile, but don't run tests --no-fail-fast Run all tests regardless of failure -p, --package <SPEC>... Package to run tests for --all Test all packages in the workspace --exclude <SPEC>... Exclude packages from the test -j, --jobs <N> Number of parallel jobs, defaults to # of CPUs --release Build artifacts in release mode, with optimizations --features <FEATURES> Space-separated list of features to activate --all-features Activate all available features --no-default-features Do not activate the `default` feature --target <TRIPLE> Build for the target triple --target-dir <DIRECTORY> Directory for all generated artifacts --manifest-path <PATH> Path to Cargo.toml --message-format <FMT> Error format [default: human] [possible values: human, json, short] -v, --verbose Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color <WHEN> Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z <FLAG>... Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details -h, --help Prints help information ARGS: <TESTNAME> If specified, only run tests containing this string in their names <args>... Arguments for the test binary The test filtering argument TESTNAME and all the arguments following the two dashes (`--`) are passed to the test binaries and thus to libtest (rustc's built in unit-test and micro-benchmarking framework). If you're passing arguments to both Cargo and the binary, the ones after `--` go to the binary, the ones before go to Cargo. For details about libtest's arguments see the output of `cargo test -- --help`. As an example, this will run all tests with `foo` in their name on 3 threads in parallel: cargo test foo -- --test-threads 3 If the `--package` argument is given, then SPEC is a package ID specification which indicates which package should be tested. If it is not given, then the current package is tested. For more information on SPEC and its format, see the `cargo help pkgid` command. All packages in the workspace are tested if the `--all` flag is supplied. The `--all` flag is automatically assumed for a virtual manifest. Note that `--exclude` has to be specified in conjunction with the `--all` flag. The `--jobs` argument affects the building of the test executable but does not affect how many jobs are used when running the tests. The default value for the `--jobs` argument is the number of CPUs. If you want to control the number of simultaneous running test cases, pass the `--test-threads` option to the test binaries: cargo test -- --test-threads=1 Compilation can be configured via the `test` profile in the manifest. By default the rust test harness hides output from test execution to keep results readable. Test output can be recovered (e.g., for debugging) by passing `--nocapture` to the test binaries: cargo test -- --nocapture To get the list of all options available for the test binaries use this: cargo test -- --help
cargo test -- --test-threads=1
並列実行しない。
cargo test -- --nocapture
プロジェクト作成。
$ cargo new my_crate --lib
コード作成。
src/lib.rs
// `cargo test -- --nocapture`コマンドを実行すると表示される fn print() { println!("***** Function!! *****"); } #[cfg(test)] mod tests { use super::*; #[test] fn it_works() { print(); assert_eq!(2 + 2, 4); } }
テスト実行。
$ cd my_crate $ cargo test -- --nocapture
println!
マクロの実行結果が表示される。
cargo test テスト関数名
指定したテスト関数を実行する。
またはテスト関数名の一部を指定すると、それに部分一致するテストすべてを実行する。
#[ignore]
#[ignore]
注釈つきのテスト関数を無視する。
#[cfg(test)] mod tests { use super::*; #[test] fn it_works() { assert_eq!(2 + 2, 4); } #[test] #[ignore] fn expensive_test() { // 実行に1時間かかるコード } }
cargo test -- --ignored
#[ignore]
注釈つきのテスト関数のみ実行する。
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
- bash 4.4.12(1)-release
- rustc 1.34.2 (6c2484dc3 2019-05-13)
- cargo 1.34.0 (6789d8a0a 2019-04-01)
$ uname -a Linux raspberrypi 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux
前回まで
- Rustを学んでみたい(プログラミング言語)
- Rustの環境構築
- RustでHelloWorld
- Rustの和訳ドキュメント
- Cargoでプロジェクト作成・ビルド・実行
- クレートとは?
- Rustで関数を使ってみる
- Rustでモジュールを使ってみる
- Rustで乱数を生成する(rand)
- Rustで標準入力する(std::io::stdin().read_line())
- RustでMatch判定する(match)
- Rustでprintとread_lineを1行にする方法
- Rustで数当てゲーム
- クレート名にドット.が使えない
- Rustの変数と可変性(let, mut) error[E0384]: cannot assign twice to immutable variable
x
- Rustのimmutable束縛とconst定数の違い
- RustのREPL、evcxrのインストールに失敗した
- Rustでコンパイルするときの変数未使用warningを消す
- Rustの変数(再代入、再宣言(シャドーイング))
- Rustのシャドーイングについて
- イミュータブルについて(副作用)
- Rustの定数(const)
- Rustのデータ型(数値)
- Rustのデータ型(論理)
- Rustのデータ型(文字)
- Rustのデータ型(タプル)
- Rustのデータ型(配列)
- Rustの関数
- Rustのif式
- Rustのくりかえし文(loop)
- Rustのくりかえし文(while)
- Rustのくりかえし文(for)
- Rustの所有権(ムーブ)
- Rustの所有権(関数)
- Rustの所有権(スライス)
- Rustの構造体(定義とインスタンス化)
- Rustの構造体(プログラム例)
- Rustの構造体(メソッド)
- Rustの列挙型(enum)
- Rustの列挙型(enum)
- Rustの列挙型(enum)
- Rustのmatch(制御フロー演算子)
- RustでNULLを扱う(Option, Some, None)
- NULL参照は10億ドルの失敗だった
- Rustの列挙型に独自表示を実装する(E0277 対策 std::fmt::Display 実装)
- RustのIfLet(matchの糖衣構文)
- Rustのプロジェクト構造
- Rustのcargoでライブラリ&テスト(単体、結合)
- Rustのモジュール(mod)
- Rustのモジュール(pub)
- Rustのmod参照方法(
mod 子モジュール名;
,use 要素名;
,extern crate クレート名;
,super
) - Rustのインポートまとめ(Rust2018)
- RustのコレクションVec型
- RustのコレクションString型
- RustのコレクションHashMap型
- Rustのコレクション(練習問題)
- Rustのエラー処理
- Rustのジェネリクス
- Rustのトレイト
- Rustのライフタイム1
- Rustのライフタイム2(構造体の定義)
- Rustのライフタイム3(ライフタイム省略)
- Rustのライフタイム4(impl定義)
- Rustの静的ライフタイム5('static)
- Rustのライフタイム6(ジェネリクス、トレイト境界とともに)
- Rustのテストコードを書く