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:
contracts
Folder: Contains smart contract files.test
Folder: The unit test files are under the test folder.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:
Checking if a value is what is expected
Checking if an event is fired with the correct arguments
Checking if a revert has occurred