【问题标题】:How to print values in tests?如何在测试中打印值?
【发布时间】:2021-02-27 07:48:57
【问题描述】:

我在 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!同时构建基板运行时。

【问题讨论】:

    标签: substrate


    【解决方案1】:

    要使用println!,您必须确保您的测试是“std”。 比如:

    #[cfg(std)]
    mod tests;
    
    // ---
    
    // But some tests are no std
    mod tests;
    

    如果你想使用info!,试试RUST_LOG=info cargo t -- --nocapture

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      相关资源
      最近更新 更多