test는 javascript 기반 테스트 프레임 워크인 mocha를 사용한다.
기본 구조
const counter = artifacts.require('./Counter.sol');
const assert = require('assert');
contract('Counter', async () => {
describe('First Contract Test', async () => {
it('Counter Test', async () => {
const instance = await counter.deployed();
const result = await instance.get();
assert.equal(response, 9, '10이 나와야 해요');
});
});
});
const counter = artifacts.require('./Counter.sol');
contract();
describe();
describe('@@@@', () => {
describe('####', () => {
});
});
it();
it("Test code message, async function() {})
const instance = await counter.deployed();
Counter Contract가 배포된 Instance를 가져온다.
const result = await instance.get();
assert.equal(response, 9, '10이 나와야 해요');
> truffle test counter.test.js
Using network 'test'.
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Contract: Counter
First Contract Test
✔ get() Test
1 passing (33ms)
> truffle test counter.test.js
Using network 'test'.
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Contract: Counter
First Contract Test
1) get() Test
> No events were emitted
0 passing (38ms)
1 failing
1) Contract: Counter
First Contract Test
get() Test:
AssertionError [ERR_ASSERTION]: 10이 나와야 해요
at Context.<anonymous> (counter.test.js:9:14)
at processTicksAndRejections (node:internal/process/task_queues:96:5)