I set up test project based on the metacoin-box (truffle unbox metacoin mc
) with two test folders
- test - has js tests
- test-solidity - has solidity tests
Test layout
╭─amal@falafel ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0› ‹›
╰─$ tree
.
├── contracts
│ ├── ConvertLib.sol
│ ├── MetaCoin.sol
│ └── Migrations.sol
├── LICENSE
├── migrations
│ ├── 1_initial_migration.js
│ └── 2_deploy_contracts.js
├── test
│ └── metacoin.js
├── test-solidity
│ └── TestMetaCoin.sol
└── truffle-config.js
4 directories, 9 files
╭─amal@falafel ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0› ‹›
╰─$ truffle test
results as expected
Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--1743274-Y2q2VdU15dGG
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
Contract: MetaCoin
✔ should put 10000 MetaCoin in the first account
✔ should call a function that depends on a linked library
✔ should send coin correctly (1077ms)
3 passing (1s)
╭─amal@falafel ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0› ‹›
╰─$ truffle test test/metacoin.js
results as expected
Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--1743388-0nsXaTr7XjbR
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
Contract: MetaCoin
✔ should put 10000 MetaCoin in the first account
✔ should call a function that depends on a linked library
✔ should send coin correctly (1063ms)
3 passing (1s)
╭─amal@falafel ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0› ‹›
╰─$ truffle test test-solidity
results as expected
Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Compiling ./test-solidity/TestMetaCoin.sol
> Artifacts written to /tmp/test--1743534-BBNscOqTSZk2
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
TestMetaCoin
✔ testInitialBalanceUsingDeployedContract (1056ms)
✔ testInitialBalanceWithNewMetaCoin (1040ms)
2 passing (20s)
╭─amal@falafel ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0› ‹›
╰─$ mkdir test-empty
╭─amal@falafel ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0› ‹›
╰─$ truffle test test-empty
Whoa, runs unspecified tests
Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /tmp/test--1744145-aVxVEeMoq6AW
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
Contract: MetaCoin
✔ should put 10000 MetaCoin in the first account
✔ should call a function that depends on a linked library
✔ should send coin correctly (1073ms)
3 passing (1s)
What does it mean when truffle test is invoked with a file and a folder?
╭─amal@falafel ~/.scratch/2022/07/18/swiss-dirs/mc ‹node-16.16.0› ‹ruby-3.0.0› ‹›
╰─$ truffle test test/metacoin.js test-solidity
???
Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Compiling ./test-solidity/TestMetaCoin.sol
> Artifacts written to /tmp/test--1749328-NBlMKvd6ADTu
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
TestMetaCoin
✔ testInitialBalanceUsingDeployedContract (1058ms)
✔ testInitialBalanceWithNewMetaCoin (1045ms)
2 passing (20s)