1 个不稳定版本
| 0.2.0 | 2022年11月27日 |
|---|
#4 in #rspec
17KB
321 行
speculate2
基于RSpec灵感的Rust最小测试框架。 (这是一个为Rust 2021更新和部分重写的分支,带有更新的依赖关系和删除的不稳定功能。)
安装
将speculate添加到您的Cargo.toml的dev-dependencies部分
[dev-dependencies]
speculate2 = "0.2"
并将以下内容添加到您想要添加测试的Rust文件的顶部
#[cfg(test)]
use speculate2::speculate; // Must be imported into the current scope.
用法
Speculate提供了speculate!语法扩展。在speculate! { ... }内,您可以有任何“Item”,如static、const、fn等,以及5种特殊的块类型
-
describe(或其别名context)- 以分层方式分组测试,以便于阅读。可以任意嵌套。 -
before和after- 包含在每个同级和嵌套的it块之前/之后插入的设置/清理代码。 -
it(或其别名test)- 包含测试。例如
it "can add 1 and 2" { assert_eq!(1 + 2, 3); }您可以可选地向此块添加属性
#[ignore] test "ignore" { assert_eq!(1, 2); } #[should_panic] test "should panic" { assert_eq!(1, 2); } #[should_panic(expected = "foo")] test "should panic with foo" { panic!("foo"); }
许可证
与原始仓库相同许可证,MIT许可证。副本可在仓库根目录中找到。
依赖项
~1.5MB
~36K SLoC