Truffle Test Generator
A utility for creating new test files in a Truffle project.
npm i @audits/truffle-test-generator --save-dev
Use Truffle to compile your contracts first.
Generate tests for a contract named MyContract.
npx ttg MyContract
Replace MyContract with the name of the contract you want to create tests for.
How It Works
The test generator will look at the json files located in the
./build/contracts directory for the given contract name. As long as that contract exists and has been compiled, a test file will be created for it.
Each test will include a standard template for the beginning of the file, which includes
requireing the artifact, declaring the contract test, and setting some common account variables.
const MyChildContract = artifacts
While reading the contract's json file, it will also generate input parameters for your constructor. However, it will be up to you to update the values as your contract requires.
// Be sure to update these constructor valueslet _initialParentValue = 0let _initialChildValue = 0
Any inherited contracts with external or public functions will have a test stub (as a describe block) created for it.
This allows you to easily have a structure for your tests and ensure that each external/public method will be tested, provided you write a test for it.
The test file will be placed in the
test directory within your Truffle project and named
MyContract_test.js, where MyContract is the name of the contract. In order to prevent a user from accidentally erasing an existing file,
-new will be appended to the name and a new file will be created if the filename already exists. If the
-new file exists, it will be overwritten.