unit-testing - 使用 WebAssembly 在 Rust 中进行单元测试
问题描述
我正在WASM
使用seed
框架编写前端。
我想用单元测试测试我的一个模块,但我不能让它们测试WASM
代码。这是我的测试套件:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn check_non_wasm() {
assert_eq!("test", "test");
}
#[test]
fn check_home() {
assert_eq!(Urls::new().home().to_string(), "/");
}
}
第一个测试通过,因为没有使用任何与WASM
. 另一个测试失败并出现以下错误:
thread 'urls::tests::check_home' panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets'
如果我运行cargo make test --chrome
它,它甚至不会看到这些测试。
我尝试运行cargo test --target wasm32-unknown-unknown
,但失败并出现以下错误:
could not execute process `C:\Users\djenty\w\frontend\target\wasm32-unknown-unknown\debug\deps\w_frontend-2b6de747c6501f70.wasm` (never executed)
rustup
显示目标已安装:
installed targets for active toolchain
--------------------------------------
wasm32-unknown-unknown
x86_64-pc-windows-msvc
active toolchain
----------------
stable-x86_64-pc-windows-msvc (default)
rustc 1.54.0 (a178d0322 2021-07-26)
我在这里想念什么?
解决方案
推荐阅读
- python - Python 循环无法遍历 html 表的所有值
- qt - 如何在不手动操作 .ui 文件的情况下在 QtDesigner 中编辑 QtElement 的网格位置?
- python - DJANGO gte, lte 没有显示任何结果
- wpf - 从 WPF-Windows (XAML) 调用 WPF-Control 中的 RelayCommand
- serialization - 如何在 Hazelcast 上安排在 IMap 上查询的任务?
- r - 如何在 R 中创建一个用户生成的函数,将列中的所有值转换为日期格式?
- firebase - Flutter/Firebase 错误 - 未处理的异常:类型 '_CompactLinkedHashSet
' 不是类型 'FutureOr 的子类型 >>' - java - AltUnityDriver create-无法执行命令'mobiledevice tunnel -u (device udid)13000 13000'
- blazor - Blazor - 在 RenderFragment 部分刷新子组件
- shell - 如何将变量从一个目录存储或捕获到另一个目录并在 Linux 中使用 cut 命令执行