I have written benchmarking functions from my pallet. How I can test these benchmarking functions please?
You have to add the following line to your benchmarking. For example like in
pallet-assets. Make sure to adjust it to your needs.
impl_benchmark_test_suite!( MyPallet, crate::mock::new_test_ext(), crate::mock::Test )
This will create a unit test for each benchmark and run it a few times with different values for each component. Starting the tests looks like this:
cargo test -p pallet-whatever --features runtime-benchmarks
test benchmarking::bench_start_lottery ... ok test benchmarking::bench_stop_repeat ... ok test benchmarking::bench_on_initialize_end ... ok test benchmarking::bench_set_calls ... ok test benchmarking::bench_buy_ticket ... ok test benchmarking::bench_on_initialize_repeat ... ok
Each line is the output of one benchmark unit-test.
Please not that benchmark tests are no-std and that normally you cannot use functions from the
mock.rs since it is std. You can, however, create a
nostd_mock.rs with helper functions that are usable from tests and benchmarks.