# Unit Test Contract

Smart contract unit tests are written in JavaScript. In this tutorial, we provide two examples of unit testing using Hardhat and Truffle.

## Unit Testing in Hardhat

<https://github.com/Fantom-foundation/unittestexample-hardhat>

## Unit Testing in Truffle

<https://github.com/Fantom-foundation/unittestexample-truffle>

Each example repository contains the following:

* &#x20;`contracts` Folder: Contains smart contract files.
* &#x20;`test` Folder: The unit test files are under the test folder.
* &#x20;`README.md` File: Contains instructions for compiling, testing, deploying, and verifying the smart contracts.

In the above examples, unit tests are included in one single JavaScript file. However, you can have as many tests and files as you need for your project. In the examples, there are three types of tests:

1. &#x20;Checking if a value is what is expected
2. &#x20;Checking if an event is fired with the correct arguments
3. &#x20;Checking if a revert has occurred


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fantom.foundation/build-on-opera/tutorials/unit-test-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
