# Good practice testing structure for a rust project

**URL:** <https://forum.dfinity.org/t/good-practice-testing-structure-for-a-rust-project/37390>\
**Category:** Developers\
**Created:** [November 16, 2024, 7:47pm UTC](https://forum.dfinity.org/t/good-practice-testing-structure-for-a-rust-project/37390 "2024-11-16T19:47:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaimebarrancos](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jaimebarrancos/32/18837_2.png) [@jaimebarrancos](https://forum.dfinity.org/u/jaimebarrancos)\
**Post date:** [November 16, 2024, 7:47pm UTC](https://forum.dfinity.org/t/good-practice-testing-structure-for-a-rust-project/37390/1 "2024-11-16T19:47:03Z")

</div>

**I want to test stuff.**

So the way I see it I have 3 options to pick from and would like to know what is usually used and what is a good practice and why. I can:

- Write rust unit tests - tests in the same file as the thing they’re testing (I don’t like this because it doesnt make sense for my canister to have the tests)
- Write integration tests in rust in a separate folder (package). But here I don’t know what libraries to use to make authenticated calls, to fake being a certain account (which is equivelent to mocking an address in evm) or maybe even to run an local IC through rust (I’m not sure if it helps or not).
- Write tests in another project entirely that call my IC instance. For example using js or something else that is completely separate from my rust environment.

Any help is appreciated

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [November 17, 2024, 7:17am UTC](https://forum.dfinity.org/t/good-practice-testing-structure-for-a-rust-project/37390/2 "2024-11-17T07:17:07Z")

</div>

> [@jaimebarrancos](#):
>
> Write integration tests in rust in a separate folder (package). But here I don’t know what libraries

For the integration test, you can use [pocket-ic](https://github.com/dfinity/pocketic).

With it, you can write tests in Rust—for example, [here](https://github.com/dfinity/oisy-wallet/tree/main/src/backend/tests/it) is the suite of OISY’s backend—but also in various other languages such as JavaScript with [pic.js](https://hadronous.github.io/pic-js/) as for example, [here](https://github.com/junobuild/juno/tree/main/src/tests) is the test suite of Juno.

I don’t know if it’s the best practice, but I believe this is a good approach to scope the tests for your backend.

> [@jaimebarrancos](#):
>
> Write tests in another project entirely that call my IC instance.

If in addition you also want to add some E2E tests because you have both a frontend and a backend that runs on an IC instance, a handy plugin to automate sign-in with II is the [internet-identity-playwright](https://github.com/dfinity/internet-identity-playwright).
