Unit testing is a type of testing an app. It is a process in which the smallest testable parts of an application, called units, are individually and independently examined for proper operation. Unit testing can be done manually but is often automated.
Truffle comes with a unit testing framework by default to automate the testing of your contracts. It provides a clean room environment when running your test files; that is, truffle will rerun all of your migrations at the beginning of every test file to ensure you have a fresh set of contracts to test against.
Truffle lets you write simple and manageable tests in two different ways:
- In JavaScript, to exercise your contracts from the app client
- In Solidity, to exercise your contracts from other contracts
Both styles of tests have their advantages and drawbacks. We will learn both ways of writing tests.
All test files should be located in the ./test directory. Truffle will run test files only with these file extensions: .js, .es, .es6, and .jsx, and .sol. All other files are ignored.