substrate - 如何在测试中打印值?
问题描述
我在 decl_module 中有以下代码
#[weight = 10_000 + T::DbWeight::get().reads_writes(1,1)]
pub fn create_deparment(origin, name: Vec<u8>, location: Vec<u8>, detail: Vec<u8>) -> dispatch::DispatchResult {
let _who = ensure_signed(origin)?;
let oldcount = DeparmentCount::get();
debug::info!("Old Deparment Count: {:?}", oldcount);
// print("Old Deparment Count");
Ok(())
}
这是我的测试:
#[test]
fn create_deparment_test() {
new_test_ext().execute_with(|| {
let _result = TemplateModule::create_deparment(Origin::signed(1), "Education".as_bytes().to_vec(), "India".as_bytes().to_vec(), "hashcode".as_bytes().to_vec());
});
}
我想在运行货物测试时在终端中打印 debug::info。
cargo test -- --nocapture
可能吗?
编辑:
打印!如果您仅使用模板箱进行测试,则可以正常工作,因此可以删除 println!在构建基板运行时。
解决方案
要使用println!
你必须确保你的测试是'std'。就像是:
#[cfg(std)]
mod tests;
// ---
// But some tests are no std
mod tests;
如果你想使用info!
试试RUST_LOG=info cargo t -- --nocapture
推荐阅读
- python - CVRP模型制定
- java - 如何解决 OutOfMemoryError: Java heap space when traversing to find all possible paths with large graph?
- html - 如何停止导航栏引起的滚动
- python - 尝试迭代 OrderedDict() 时,错误无法解压不可迭代
- python - TypeError:无法将 builtin_function_or_method 转换为张量或操作
- javascript - 如何使用正则表达式获取 Aadhar 号码的最后一个字符
- c++ - 如何在 void 函数和 do-while 循环 C++ 中回显输入
- javascript - 如何垂直对齐容器中的文本,
- android - 我的 android 应用程序可以在某些设备上运行,而其他相同类型的应用程序在工厂休息之前无法运行
- c++ - 堆栈本地对象的使用和对象的销毁之间是否存在发生关系?