# `sweettest`
Ergonomic test framework for testing Holochain DNAs in Rust
_by @maackle_
---
## `sweettest` vs. `tryorama`
----
- `tryorama`
- tests are written in JS
- spawns a separate Conductor process, and talks to it over a Websocket using the Conductor API
- `sweettest`
- tests are written in pure Rust
- runs a Conductor in-process and talks to it using simple function calls
- this means you can use the Rust types defined in your Zome directly
----
## What does sweettest provide that tryorama doesn't?
- <small>You can write tests in terms of types from zome code, rather than using JSON-serialized representations</small>
- <small>Your test code is more likely to stay in sync with your zome code, since they are both type-checked together</small>
- <small>You can define an on-the-fly `InlineZome` in Rust to mix in to your normal Dna</small>
- <small>There is no ergonomic way to do this yet, but it can be done!</small>
----
## Inline Zomes
```rust=
let entry_def = EntryDef::default_with_id("entrydef");
InlineZome::new_unique(vec![entry_def.clone()])
.callback("create", move |api, ()| {
let entry_def_id: EntryDefId = entry_def.id.clone();
let entry = Entry::app(().try_into().unwrap()).unwrap();
let hash = api.create(CreateInput::new(
entry_def_id,
entry,
ChainTopOrdering::default(),
))?;
Ok(hash)
})
.callback("read", |api, hash: HeaderHash| {
api.get(vec![GetInput::new(hash.into(), GetOptions::default())])
.map(|e| e.into_iter().next().unwrap())
.map_err(Into::into)
})
```
---
## Migrating to sweettest
This example explains a lot of the translation needed
[tryorama](https://github.com/holochain/elemental-chat/blob/sweettest-example/tests/src/basic-chatting.ts) → [sweettest](https://github.com/holochain/elemental-chat/blob/sweettest-example/zomes/chat/tests/basic_chatting.rs)
----
## [sweettest docs](https://docs.rs/holochain/0.0.109/holochain/sweettest/index.html)
---
have a sweet day :lollipop:
{"metaMigratedAt":"2023-06-16T12:02:37.782Z","metaMigratedFrom":"Content","title":"`sweettest`","breaks":true,"contributors":"[{\"id\":\"efe1b17f-884b-44a9-a1f0-e9ea364a94de\",\"add\":3001,\"del\":895}]"}