Tutorial
Unit Testing with Hardhat
12 steps
In this tutorial, we’ll focus on one of the core reasons for using Hardhat - testing smart contracts! Only proceed with this tutorial once you have completed Introduction to Hardhat as we’ll be continuing from the su-hardhat-module directory where we left off from.
Helpful prior knowledge
- Pre-existing knowledge of Javascript will be helpful, but not necessary
- Knowledge of Solidity is a bonus as well
Learning Outcomes
By the end of this tutorial, you will be able to:
- Describe what unit tests are
- Compile smart contracts using Hardhat
- Write unit tests using Hardhat
Tutorial Steps
Total steps: 12
-
Step 1: What is Unit Testing
-
Step 2: Sample Smart Contract
-
Step 3: Compiling Smart Contract
-
Step 4: Installing Plugins
-
Step 5: Create Empty Test Script
-
Step 6: Initialisation & beforeEach()
-
Step 7: Deployment Tests
-
Step 8: Describe(), async() & await
-
Step 9: Running the Tests
-
Step 10: Testing the Transfer Functionality - Basics
-
Step 11: Testing the Transfer Functionality - Specify Caller
-
Step 12: Testing the Transfer Functionality - Negative Case Test
Find articles to support you through your journey or chat with our support team.
Help Center