Holochain Forum

Unit testing Zomes with MockHDK

How To Setup

-> for now, see my work in progress:

Special For VS Code

I had a bit of a hard time configuring it, to fully use the Rust analyzer convenience access to the test runners. (where it says “Run Test” in the screenshots)

You might see these issues, if you are using VS Code, and Rust analyzer extension.

There is a Rust “feature” that must be enabled

This was visible to me in the bash script he had set up for executing the tests, but I was struggling to figure out where all to set it, to get my VS Code playing nicely

This was the script:

cargo test -j 2 --manifest-path happ/zomes/points/Cargo.toml --lib --features="mock"

You will need this in your Cargo.toml for one thing:

default = []
mock = ["hdk/mock"]

But there is also this hidden feature of Rust analyzer where in preferences you can toggle on Rust features, so we can use this. Click Add Item

type in mock and hit ok

Then reload your VS Code

No more problem with MockHdkT not found


@Connoropolous thanks once again for smoothing over the cracks in my work :sweat_smile:

hope you enjoy mocking your validation rules!