substrate 编译出错unresolved import `sp_runtime::testing` failed to resolve: could not find `GenesisConfig` in `system`
error[E0432]: unresolved import `sp_runtime::testing` --> /Users/suyinrong/bitcoin-proj/substrate-course/substrate-node-template/pallets/poe/src/mock.rs:5:41 | 5 | traits::{BlakeTwo256, IdentityLookup}, testing::Header, Perbill, | ^^^^^^^ could not find `testing` in `sp_runtime` error[E0433]: failed to resolve: could not find `GenesisConfig` in `system` --> /Users/suyinrong/bitcoin-proj/substrate-course/substrate-node-template/pallets/poe/src/mock.rs:66:10 | 66 | system::GenesisConfig::default().build_storage::<Test>().unwrap().into() | ^^^^^^^^^^^^^ could not find `GenesisConfig` in `system` error[E0412]: cannot find type `Box` in this scope --> /Users/suyinrong/bitcoin-proj/substrate-course/substrate-node-template/pallets/poe/src/mock.rs:10:1 | 10 | / impl_outer_origin! { 11 | | pub enum Origin for Test {} 12 | | } | |_^ not found in this scope | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) help: consider importing one of these items | 1 | use crate::Box; | 1 | use frame_support::traits::Box; | 1 | use sp_std::boxed::Box; | error[E0433]: failed to resolve: use of undeclared type `Box` --> /Users/suyinrong/bitcoin-proj/substrate-course/substrate-node-template/pallets/poe/src/mock.rs:10:1 | 10 | / impl_outer_origin! { 11 | | pub enum Origin for Test {} 12 | | } | |_^ not found in this scope | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) help: consider importing one of these items | 1 | use crate::Box; | 1 | use frame_support::traits::Box; | 1 | use sp_std::boxed::Box; | error[E0433]: failed to resolve: use of undeclared type `Box` --> /Users/suyinrong/bitcoin-proj/substrate-course/substrate-node-template/pallets/poe/src/mock.rs:10:1 | 10 | / impl_outer_origin! { 11 | | pub enum Origin for Test {} 12 | | } | |_^ not found in this scope | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) help: consider importing one of these items | 1 | use crate::Box; | 1 | use frame_support::traits::Box; | 1 | use sp_std::boxed::Box; | error[E0433]: failed to resolve: use of undeclared type `Box` --> /Users/suyinrong/bitcoin-proj/substrate-course/substrate-node-template/pallets/poe/src/mock.rs:10:1 | 10 | / impl_outer_origin! { 11 | | pub enum Origin for Test {} 12 | | } | |_^ not found in this scope | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) help: consider importing one of these items | 1 | use crate::Box; | 1 | use frame_support::traits::Box; | 1 | use sp_std::boxed::Box; | error[E0412]: cannot find type `TestExternalities` in crate `sp_io` --> /Users/suyinrong/bitcoin-proj/substrate-course/substrate-node-template/pallets/poe/src/mock.rs:65:33 | 65 | pub fn new_test_ext() -> sp_io::TestExternalities { | ^^^^^^^^^^^^^^^^^ not found in `sp_io` error: aborting due to 7 previous errors Some errors have detailed explanations: E0412, E0432, E0433. For more information about an error, try `rustc --explain E0412`. error: could not compile `pallet-poe` To learn more, run the command again with --verbose.
遇见此类错误信息是因为,在你的测试mod上面需要加上#[cfg(test)]
例如我这里就是在mod mork上没有添加此类设置报错。