- Creating a project
- Choosing an Ethereum client
- Compiling contracts
- Running migrations
- Testing your contracts
- Writing tests in Solidity
- Interacting with your contracts
- Package management via EthPM
- Package management via NPM
- Debugging your contracts
- Using the console
- Writing external scripts
- Using the build pipeline
- Contact the developers
Truffle comes standard with an automated testing framework to make testing your contracts a breeze. This framework lets you write simple and manageable tests in two different ways:
- In Solidity, for exercising your contracts in advanced, bare-to-the-metal scenarios.
Both styles of tests have their advantages and drawbacks. See the next two sections for a discussion of each one.
All test files should be located in the
./test directory. Truffle will only run test files with the following file extensions:
.sol. All other files are ignored.
To run all tests, simply run:
$ truffle test
Alternatively, you can specify a path to a specific file you want to run, e.g.,
$ truffle test ./path/to/test/file.js
Truffle provides a clean room environment when running your test files. When running your tests against the TestRPC, Truffle will use the TestRPC's advanced snapshotting features to ensure your test files don't share state with each other. When running against other Ethereum clients like go-ethereum, Truffle will re-deploy all of your migrations at the beginning of every test file to ensure you have a fresh set of contracts to test against.
The EthereumJS TestRPC is significantly faster than other clients when running automated tests. Moreover, the TestRPC contains special features which Truffle takes advantage of to speed up test runtime by almost 90%. As a general workflow, we recommend you use the TestRPC during normal development and testing, and then run your tests once against go-ethereum or another official Ethereum client when you're gearing up to deploy to live or production networks.