Pallets can have unit tests with a mock runtime where extrinsics are tested against multiple cases.

However it's not obvious how to do the same for offchain workers.

How can I write unit tests for offchain workers?

1 Answer 1


You need something like this to register the offchain ext.

It's a really good example. Check the whole tests.rs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.