Rust 学习笔记:控制测试的运行方式

Rust编程语言代码详细运行、编译方法 根据你所使用的操作系统(如 Windows、Linux、macOS),按照官方提供的安装指南进行操作。通常,在大多数系统上,安装过程会自动配置好 Rust 编译器(rustc)以及包管理器(cargo)等必要工具。 阅读详情

Rust 学习笔记:控制测试的运行方式

cargo test 生成的二进制文件的默认行为是并行运行所有测试,并捕获测试运行期间生成的输出,从而防止显示输出,并使读取与测试结果相关的输出变得更容易。但是,可以指定命令行选项来更改此默认行为。

列出用于测试二进制文件的参数:

cargo test --help
Execute all unit and integration tests and build examples of a local package

Usage: cargo.exe test [OPTIONS] [TESTNAME] [-- [ARGS]...]

Arguments:
  [TESTNAME]  If specified, only run tests containing this string in their names
  [ARGS]...   Arguments for the test binary

Options:
      --no-run                   Compile, but don't run tests
      --no-fail-fast             Run all tests regardless of failure
      --future-incompat-report   Outputs a future incompatibility report at the end of the build
      --message-format <FMT>     Error format
  -q, --quiet                    Display one character per test instead of one line
  -v, --verbose...               Use verbose output (-vv very verbose/build.rs output)
      --color <WHEN>             Coloring: auto, always, never
      --config <KEY=VALUE|PATH>  Override a configuration value
  -Z <FLAG>                      Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
  -h, --help                     Print help

Package Selection:
  -p, --package [<SPEC>]  Package to run tests for
      --workspace         Test all packages in the workspace
      --exclude <SPEC>    Exclude packages from the test
      --all               Alias for --workspace (deprecated)

Target Selection:
      --lib               Test only this package's library
      --bins              Test all binaries
      --bin [<NAME>]      Test only the specified binary
      --examples          Test all examples
      --example [<NAME>]  Test only the specified example
      --tests             Test all targets that have `test = true` set
      --test [<NAME>]     Test only the specified test target
      --benches           Test all targets that have `bench = true` set
      --bench [<NAME>]    Test only the specified bench target
      --all-targets       Test all targets (does not include doctests)
      --doc               Test only this library's documentation

Feature Selection:
  -F, --features <FEATURES>  Space or comma separated list of features to activate
      --all-features         Activate all available features
      --no-default-features  Do not activate the `default` feature

Compilation Options:
  -j, --jobs <N>                Number of parallel jobs, defaults to # of CPUs.
  -r, --release                 Build artifacts in release mode, with optimizations
      --profile <PROFILE-NAME>  Build artifacts with the specified profile
      --target [<TRIPLE>]       Build for the target triple
      --target-dir <DIRECTORY>  Directory for all generated artifacts
      --unit-graph              Output build graph in JSON (unstable)
      --timings[=<FMTS>]        Timing output formats (unstable) (comma separated): html, json

Manifest Options:
      --manifest-path <PATH>  Path to Cargo.toml
      --lockfile-path <PATH>  Path to Cargo.lock (unstable)
      --ignore-rust-version   Ignore `rust-version` specification in packages
      --locked                Assert that `Cargo.lock` will remain unchanged
      --offline               Run without accessing the network
      --frozen                Equivalent to specifying both --locked and --offline

Run `cargo help test` for more detailed information.
Run `cargo test -- --help` for test binary options.

列出用于测试二进制文件的选项:

cargo test -- --help
Usage: C:\Users\81228\Documents\Program\Rust Project\adder\target\debug\deps\adder-ca62dcededf22ef1.exe [OPTIONS] [FILTERS...]

Options:
        --include-ignored 
                        Run ignored and not ignored tests
        --ignored       Run only ignored tests
        --force-run-in-process
                        Forces tests to run in-process when panic=abort
        --exclude-should-panic
                        Excludes tests marked as should_panic
        --test          Run tests and not benchmarks
        --bench         Run benchmarks instead of tests
        --list          List all tests and benchmarks
    -h, --help          Display this message
        --logfile PATH  Write logs to the specified file (deprecated)
        --nocapture     don't capture stdout/stderr of each task, allow
                        printing directly
        --test-threads n_threads
                        Number of threads used for running tests in parallel
        --skip FILTER   Skip tests whose names contain FILTER (this flag can
                        be used multiple times)
    -q, --quiet         Display one character per test instead of one line.
                        Alias to --format=terse
        --exact         Exactly match filters rather than by substring
        --color auto|always|never
                        Configure coloring of output:
                        auto = colorize if stdout is a tty and tests are run
                        on serially (default);
                        always = always colorize output;
                        never = never colorize output;
        --format pretty|terse|json|junit
                        Configure formatting of output:
                        pretty = Print verbose output;
                        terse = Display one character per test;
                        json = Output a json document;
                        junit = Output a JUnit document
        --show-output   Show captured stdout of successful tests
    -Z unstable-options Enable nightly-only flags:
                        unstable-options = Allow use of experimental features
        --report-time   Show execution time of each test.
                        Threshold values for colorized output can be
                        configured via
                        `RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION`
                        and
                        `RUST_TEST_TIME_DOCTEST` environment variables.
                        Expected format of environment variable is
                        `VARIABLE=WARN_TIME,CRITICAL_TIME`.
                        Durations must be specified in milliseconds, e.g.
                        `500,2000` means that the warn time
                        is 0.5 seconds, and the critical time is 2 seconds.
                        Not available for --format=terse
        --ensure-time   Treat excess of the test execution time limit as
                        error.
                        Threshold values for this option can be configured via
                        `RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION`
                        and
                        `RUST_TEST_TIME_DOCTEST` environment variables.
                        Expected format of environment variable is
                        `VARIABLE=WARN_TIME,CRITICAL_TIME`.
                        `CRITICAL_TIME` here means the limit that should not
                        be exceeded by test.
        --shuffle       Run tests in random order
        --shuffle-seed SEED
                        Run tests in random order; seed the random number
                        generator with SEED


The FILTER string is tested against the name of all tests, and only those
tests whose names contain the filter are run. Multiple filter strings may
be passed, which will run all tests matching any of the filters.

By default, all tests are run in parallel. This can be altered with the
--test-threads flag or the RUST_TEST_THREADS environment variable when running
tests (set it to 1).

By default, the tests are run in alphabetical order. Use --shuffle or set
RUST_TEST_SHUFFLE to run the tests in random order. Pass the generated
"shuffle seed" to --shuffle-seed (or set RUST_TEST_SHUFFLE_SEED) to run the
tests in the same order again. Note that --shuffle and --shuffle-seed do not
affect whether the tests are run in parallel.

All tests have their standard output and standard error captured by default.
This can be overridden with the --nocapture flag or setting RUST_TEST_NOCAPTURE
environment variable to a value other than "0". Logging is not captured by default.

Test Attributes:

    `#[test]`        - Indicates a function is a test to be run. This function
                       takes no arguments.
    `#[bench]`       - Indicates a function is a benchmark to be run. This
                       function takes one argument (test::Bencher).
    `#[should_panic]` - This function (also labeled with `#[test]`) will only pass if
                        the code causes a panic (an assertion failure or panic!)
                        A message may be provided, which the failure string must
                        contain: #[should_panic(expected = "foo")].
    `#[ignore]`       - When applied to a function which is already attributed as a
                        test, then the test runner will ignore these tests during
                        normal test runs. Running with --ignored or --include-ignored will run
                        these tests.
   Doc-tests adder
Usage: rustdoctest [OPTIONS] [FILTERS...]

Options:
        --include-ignored
                        Run ignored and not ignored tests
        --ignored       Run only ignored tests
        --force-run-in-process
                        Forces tests to run in-process when panic=abort
        --exclude-should-panic
                        Excludes tests marked as should_panic
        --test          Run tests and not benchmarks
        --bench         Run benchmarks instead of tests
        --list          List all tests and benchmarks
    -h, --help          Display this message
        --logfile PATH  Write logs to the specified file (deprecated)
        --nocapture     don't capture stdout/stderr of each task, allow
                        printing directly
        --test-threads n_threads
                        Number of threads used for running tests in parallel
        --skip FILTER   Skip tests whose names contain FILTER (this flag can
                        be used multiple times)
    -q, --quiet         Display one character per test instead of one line.
                        Alias to --format=terse
        --exact         Exactly match filters rather than by substring
        --color auto|always|never
                        Configure coloring of output:
                        auto = colorize if stdout is a tty and tests are run
                        on serially (default);
                        always = always colorize output;
                        never = never colorize output;
        --format pretty|terse|json|junit
                        Configure formatting of output:
                        pretty = Print verbose output;
                        terse = Display one character per test;
                        json = Output a json document;
                        junit = Output a JUnit document
        --show-output   Show captured stdout of successful tests
    -Z unstable-options Enable nightly-only flags:
                        unstable-options = Allow use of experimental features
        --report-time   Show execution time of each test.
                        Threshold values for colorized output can be
                        configured via
                        `RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION`
                        and
                        `RUST_TEST_TIME_DOCTEST` environment variables.
                        Expected format of environment variable is
                        `VARIABLE=WARN_TIME,CRITICAL_TIME`.
                        Durations must be specified in milliseconds, e.g.
                        `500,2000` means that the warn time
                        is 0.5 seconds, and the critical time is 2 seconds.
                        Not available for --format=terse
        --ensure-time   Treat excess of the test execution time limit as
                        error.
                        Threshold values for this option can be configured via
                        `RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION`
                        and
                        `RUST_TEST_TIME_DOCTEST` environment variables.
                        Expected format of environment variable is
                        `VARIABLE=WARN_TIME,CRITICAL_TIME`.
                        `CRITICAL_TIME` here means the limit that should not
                        be exceeded by test.
        --shuffle       Run tests in random order
        --shuffle-seed SEED
                        Run tests in random order; seed the random number
                        generator with SEED


The FILTER string is tested against the name of all tests, and only those
tests whose names contain the filter are run. Multiple filter strings may
be passed, which will run all tests matching any of the filters.

By default, all tests are run in parallel. This can be altered with the
--test-threads flag or the RUST_TEST_THREADS environment variable when running
tests (set it to 1).

By default, the tests are run in alphabetical order. Use --shuffle or set
RUST_TEST_SHUFFLE to run the tests in random order. Pass the generated
"shuffle seed" to --shuffle-seed (or set RUST_TEST_SHUFFLE_SEED) to run the
tests in the same order again. Note that --shuffle and --shuffle-seed do not
affect whether the tests are run in parallel.

All tests have their standard output and standard error captured by default.
This can be overridden with the --nocapture flag or setting RUST_TEST_NOCAPTURE
environment variable to a value other than "0". Logging is not captured by default.

Test Attributes:

    `#[test]`        - Indicates a function is a test to be run. This function
                       takes no arguments.
    `#[bench]`       - Indicates a function is a benchmark to be run. This
                       function takes one argument (test::Bencher).
    `#[should_panic]` - This function (also labeled with `#[test]`) will only pass if
                        the code causes a panic (an assertion failure or panic!)
                        A message may be provided, which the failure string must
                        contain: #[should_panic(expected = "foo")].
    `#[ignore]`       - When applied to a function which is already attributed as a
                        test, then the test runner will ignore these tests during
                        normal test runs. Running with --ignored or --include-ignored will run
                        these tests.

并行或连续运行测试

默认情况下测试使用线程并行运行,因此必须确保测试不依赖于彼此或任何共享状态。

如果不希望并行运行测试,或者希望对所使用的线程数进行更细粒度的控制,则可以将 --test-threads 标志和想要使用的线程数发送到测试二进制文件。请看下面的例子:

cargo test -- --test-threads=1

我们将测试线程的数量设置为 1,测试变成串行运行。

显示函数输出

默认情况下,如果测试通过,Rust 的测试库将捕获打印到标准输出的所有内容。

如果我们在测试中调用 println!,测试通过了,我们将只看到表示测试通过的那一行,不会看到输出。如果测试失败,我们将看到打印到标准输出的内容以及失败消息的其余部分。

示例:

fn prints_and_returns_10(a: i32) -> i32 {
    println!("I got the value {a}");
    10
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn this_test_will_pass() {
        let value = prints_and_returns_10(4);
        assert_eq!(value, 10);
    }

    #[test]
    fn this_test_will_fail() {
        let value = prints_and_returns_10(8);
        assert_eq!(value, 5);
    }
}

运行 cargo test,我们看到只有在测试失败时,才会打印 prints_and_returns_10 函数中的输出。在测试成功时,输出被测试捕获,不打印。

在这里插入图片描述

如果我们也想看到通过测试的打印值,我们可以告诉 Rust 也显示成功测试的输出,使用 --show-output:

cargo test -- --show-output

在这里插入图片描述

按名称运行测试的子集

将要运行的测试的名称传递给 cargo test 作为参数,可以指定测试函数。

示例:

pub fn add_two(a: usize) -> usize {
    a + 2
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn add_two_and_two() {
        let result = add_two(2);
        assert_eq!(result, 4);
    }

    #[test]
    fn add_three_and_two() {
        let result = add_two(3);
        assert_eq!(result, 5);
    }

    #[test]
    fn one_hundred() {
        let result = add_two(100);
        assert_eq!(result, 102);
    }
}

我们可以将任何一个测试函数的名称传递给 cargo test,只运行该测试:

在这里插入图片描述

我们不能以这种方式指定多个测试的名称,但可以指定测试名称的一部分,并且任何名称与该值匹配的测试都将运行。例如,由于我们的两个测试的名称包含 add,我们可以通过运行 cargo test add 来运行这两个测试:

在这里插入图片描述

示例:

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }

    #[test]
    #[ignore]
    fn expensive_test() {
        // code that takes an hour to run
    }
}

除非特别要求,否则忽略某些测试

有时,执行一些特定的测试可能非常耗时,可以使用 ignore 属性进行注释以排除它们,如下所示:

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }

    #[test]
    #[ignore]
    fn expensive_test() {
        // code that takes an hour to run
    }
}

在 #[test] 之后,向想要排除的测试添加 #[ignore] 行。

如果我们只想运行被忽略的测试,可以使用:

cargo test -- --ignored

如果要运行所有测试,无论它们是否被忽略,可以运行:

cargo test -- --include-ignored
The Rust Programming Language - 第11章 测试 - 11.2 控制测试如何运行 11 测试 编写自动化测试 程序的正确性代码如我们期望的那样运行,Rust也在语言本身包含了编写软件测试的支持 本章我们会讲到编写测试时用到的注解和宏,运行测试的默认行为和选项,以及如何将测试组织成单元测试和集成测试 10.2 控制测试如何运行 cargo test在测试模式下编译代码并运行生成的测试二进制文件 并行或连续的运行测试 Rust默认使用线程来并行运行多个测试,因此测试之间不能相互依赖、或依赖任何共享的状态,包括依赖共享的环境,比如当前工作目录或者环境变量 但是如果你不希望测试并行运行,或者想要 阅读详情

相关推荐

【Rust测试】Rust代码测试方法详解与应用实战

测试是软件开发中不可或缺的重要环节,它能够确保代码质量、减少bug并提高软件的可靠性。 Rust语言从设计之初就内置了对测试的支持,提供了完善的测试框架和工具链。 本文将全面介绍Rust中的测试方法,从基础概念到高级技巧,并结合实际案例展示如何在Rust项目中实施有效的测试策略。

景天科技苑 4万+

Rust开发环境搭建到运行第一个程序HelloRust

Rust 语言是一种高效、可靠的通用高级语言。其高效不仅限于开发效率,它的执行效率也是令人称赞的,是一种少有的兼顾开发效率和执行效率的语言。 Rust 语言由 Mozilla 开发,最早发布于2014年 9月。Rust 的编译器是在 MIT License 和 Apache License 2.0 双重协议声明下的免费开源软件。 Rust 语言代码文件后缀名为**.rs**, 如**hello.rs**。

Sherry 3133

OPTEE RUST支持&构建并运行支持RUST的CA和TA

RUST语言,由于其更安全的编程语言特性,OPTEE作为可信执行环境的开源实现也增加了对RUST的支持。那么如何构建并运行支持RUST的CA和TA呢,本博客来探讨并进行qemu环境的实际演示。

AI-安全-功耗 1067

01-开始Rust之旅

官方推荐使用rustup下载 Rust,这是一个管理 Rust 版本和相关工具的命令行工具。下载时需要连接互联网。这边提供了离线安装版本。本人学习的机器环境为: ubuntu x86_64,因此选用第②个工具链;1.2.

CSDN爱好者的独到见解 2278

复古与新生:老毛子Padavan固件在旧设备上的现代化应用之旅

本文探讨了如何通过刷入Padavan固件,让小米路由器3G(R3G)等老旧设备重获新生,实现现代化应用。详细介绍了从硬件潜力分析、智能家居中枢搭建,到轻量级服务器部署和网络功能扩展的全过程,为技术爱好者提供了一条低成本、高性能的设备改造之路。

k8s6orchestrator的博客 1071

UE5 C++教程(一、基本结构)

虚幻API由三块组成,分别是Runtime,Developer utilitiew,functionality for the Editor,大多数游戏性编程只使用运行时模块,最常见的三个是Corn、CornUObject和Engine。

skycol的博客 1万+

Rust语言:安装、运行与调试

Rust是一种为系统编程设计的编程语言,它强调安全性、并发性和内存效率。本文将会介绍在多平台上安装Rust,以及如何运行和调试Rust程序。

qimablue的博客 2192

Figma 设计稿转前端代码:Cursor 实现 UI 还原的 4 种精准映射方法

揭示 Figma 设计稿转前端代码失效的根本原因在于四层语义未对齐(像素→布局、视觉→样式、交互→行为、意图→架构),提出以语义标注为核心的结构化喂数据方法,详解通过图层命名、Description 字段和 Markdown 上下文锚点实现高精度 React 组件生成,并给出可落地的避坑指南与实测提

weixin_42545292的博客 141

Rust能力养成之(16)文档化

前言 无需质疑,文档化(Documentation)在开发过程中非常重要。在开源社区,可以得到广泛应用的项目,其文档化水平都至少是合格的。我们的代码,对别人而言,应该是可读的,其中可以体现工作的目的,如此设计的原因,以及一些示例用法。可以这么说,具有完整自述文件README.md的项目,往往也都会运转良好。 因此,毫无例外,Rust社区非常重视文档,并在不同级别上提供了各种工具,以使编写代码文档变得容易。同时这些工具也考虑了用户体验方面的内容。对于编写文档,支持markdown,而Mar...

qq_40433634的博客 782

基于BP神经网络PID控制的电机转速控制器设计复现

摘要:本文提出了一种基于BP神经网络PID控制的永磁同步电机转速控制方法,通过MATLAB/Simulink平台实现了算法复现。系统采用三层BP神经网络在线调整PID参数,包含输入层(误差、误差变化率、误差积分)、5节点隐含层和输出层(Kp、Ki、Kd)。仿真结果表明,相比传统PID控制,该方案具有更快的响应速度(上升时间减少约40%)、更小的超调量(降低约60%)和更强的抗干扰能力,在电动汽车电机驱动等复杂工况下表现优异。文中详细给出了PMSM数学模型建立、BP网络设计、权值更新算法及Simulink仿真

max500600的博客 310

Open3D 计算FPFH特征【2025最新版】

FPFH特征描述子的python实现,本文最新更新时间为:2025年3月18日。

点云侠的博客 5284

深入探究 Rust 测试:灵活控制测试的执行方式

Rust 的 `cargo test` 命令默认会并行执行所有测试并捕获标准输出,这对大多数场景而言足够高效且输出整洁。然而,当项目变大、测试数增多或需处理特定场景(如依赖外部资源)时,我们常需要更精细地控制测试的执行方式。

hello.reader 1207

C语言中errno与perror()函数

宏errno和perror()函数都是在stdlib.h中定义的。 1 stdlib.h头文件 stdlib.h头文件即standard library标准库函数头文件,包含了C、C++语言的最常用的系统函数,该文件中还包含了C语言标准库函数的定义。 2 errno宏 errno宏在stdlib.h中的定义为 #define errno (*_errno()) errno宏用于保存程...

hou09tian的博客 1万+

Rust之自动化测试(二):控制测试如何运行

Rust之自动化测试(二), 控制测试如何运行

wing的专栏 820

基于STM32、HAL库的ADE7880ACPZ-RL电能计量芯片驱动程序设计

@retval 状态 (ADE7880_OK或ADE7880_ERROR)* @retval 状态 (ADE7880_OK或ADE7880_ERROR)* @retval 状态 (ADE7880_OK或ADE7880_ERROR)* @retval 状态 (ADE7880_OK或ADE7880_ERROR)* @retval 状态 (ADE7880_OK或ADE7880_ERROR)PA6 (MISO) <--> SDO (SPI数据输出)PB0 (CS) <--> /CS (片选,低有效)

corlin6688的博客 673

openclaw 保姆级部署与核心玩法解析:国产DeepSeek模型 + 飞书

OpenClaw是一款功能强大的开源AI个人助理,支持全平台私有化部署,数据完全本地掌控。它不仅可通过聊天窗口直接操控电脑(安装软件、创建项目),还支持接入飞书等主流通讯工具,化身24小时在线的智能助理。本文提供了从零开始的详细部署教程,涵盖基础安装、模型配置(如GLM-4、DeepSeek)到飞书集成的完整实战指南,助你将这款“核动力”AI助手快速融入日常工作流。

甘蓝的专栏 3007

Rust编写测试及控制执行

format!("Hello {}!(result.contains("孙飞"));使用cargo testfailures:thread 'tests::greeting_contains_name' panicked at 'assertion failed: result.contains(\"孙飞\")' , src/lib.rs:12:9failures:let target = "孙飞";assert!

m0_52796585的博客 1488

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Rust 学习笔记:我的第一个 Rust 程序

Rust 学习笔记:我的第一个 Rust 程序

ProgramNovice的博客 753

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Rust从0到1实战系列篇 并行或顺序运行测试

Rust 的测试功能提供了一个确保即使你改变了函数的实现方式,也能继续以期望的方式运行的途径。单元测试独立地验证库的不同部分,也能够测试私有函数实现细节。集成测试则检查多个部分是否能结合起来正确地工作,并像其他外部代码那样测试库的公有 API。即使 Rust 的类型系统和所有权规则可以帮助避免某些类型的 bug,不过测试对于减少代码中不符合期望行为的逻辑 bug 仍然是很重要的。

m0_68635815的博客 890

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Rust 单元测试详细教程

Rust单元测试简明教程:测试代码通常放在#[cfg(test)]模块中,使用#[test]标记测试函数。核心断言宏包括assert!、assert_eq!和assert_ne!,可通过#[should_panic]测试预期panic。支持测试私有函数、条件编译和测试忽略功能。运行测试时可控制线程数、显示输出或执行特定测试。高级技巧包括使用mockall模拟对象、speculoos实现BDD风格测试,以及通过cargo tarpaulin检查测试覆盖率。典型示例展示了计数器结构体的基础测试方法,包含正常测试

本博客分享软硬件一体化开发实战。硬件涵盖 PCB 设计、STM32 等 MCU 底层开发;软件包含 C++、Rust,Qt/QML、PyQt、Slint、TouchGFX、LVGL 各类 GUI 框架。方便软硬件开发者查阅学习。欢迎关注! 1735

rules_rust测试框架深度解析:如何编写和运行rust_test与rust_test_suite

rules_rust是Bazel构建系统中用于Rust项目的强大规则集,提供了完善的测试框架支持。本文将详细介绍如何使用`rust_test`和`rust_test_suite`规则编写和运行Rust测试,帮助开发者构建可靠的测试流程。 ## 一、快速了解rust_test:单文件测试的终极方案 `rust_test`规则是rules_rust中最基础也最常用的测试规则,用于为单个Rust源文

gitblog_01066的博客 514

Rust学习第九天——控制测试运行

学着学着不知道自己为什么学了,算了,继续吧,学都学了。

yryryrkkx的博客 946

【Rust】——编写自动化测试

🎯控制测试如何运行 🎃并行或连续的运行测试 🎃显示函数输出 🎯按测试的名称进行测试 🎯忽略测试

shsjssnn的博客 1673

【RUST学习】测试

可以向assert!、assert_eq!、assert_ne!添加可选的自定义消息—这些自定义消息和失败消息都会打印出来—assert!:第一参数必填,自定义消息作为第二个参数。—assert_eq!和assert_ne!: 前两个参数必填,自定义消息作为第三个参数。—自定义消息参数会被传递给format!宏,可以使用{}占位符format!("hello {}!result。

qq_54384621的博客 1964

《Rust权威指南》读书笔记10 - 编写自动化测试

测试是保障程序正确性的重要手段。功能上的漏洞不能直接被编译器检测和捕获,必须通过执行一些测试例并比较期望结果得出。手动编写测试用例是一个较为冗长繁琐的过程,Rust提供了一些自动化测试方法,能够标准化、高效化进行功能的自动测试。

Zheng__Huang的博客 1523

Rust语言的单元测试

目标 Rust语言 自身有单元测试机制。 简单来说: 先通过 #[test] 这个 Attribute 来标记用于测试的函数。 然后使用cargo test命令来自动运行所有的单元测试。 本篇的目标是试用这个机制。 待测试的函数 待测试的函数是:使用“欧几里得算法”(又称辗转相除法) 来求两个数的最大公约数。 代码来自于《Rust程序设计》: fn gcd(mut n: u64, mut m: u64) -> u64 { while m != 0 { if m &

主要记录了工作之余胡乱学习的知识,大部分是入门级别的内容。 主要是为了自己未来有用到时能快速上手,相当于是个备忘录。 当然,也很开心其他人可以从中找到对自己有用的信息。^_^ 1905
上一篇: Rust 学习笔记:关于生命周期的练习题
下一篇: Rust 学习笔记:编写自动化测试
UestcXiye
博客等级 码龄8年 9043粉丝 1306原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

UestcXiye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址