Guidelines
- Introduction
- Installation
- Quick Start
Guides
- Introductions
- Build local test node
- Smart Contract - ABI Files
- Smart Contract——JS Contract
- Deploy Contracts
- Test Contract
- Develop DApp Client
Smart Contracts
- Contract Introduction
- ABI File
- Database
- Account Authority
- Call In-contract
- Notification
System Contracts
- Resources
- Account
- Permission
Token Contracts
- Transfer
- Token
- Token Exchange
- Contract Sub-Wallet
Node Guide
- Node Introduction
- Add to nodes network
- Node Data Persistence
Access Guide
- FO 接入安全指南
Test Contract
A developer who does not write automated test cases is not a good test developer. We advocate for complete automated test cases at the beginning of all projects developments. With the development of the project, this early-stage investment will be heavily rewarded with returns hundreds of times the initial.
Next, we will use the FIBOS test framework to write the corresponding test cases in terms of the todo contract written in the foregoing article.
Create a new test
folder, and save the code to test/index.js
:
Definition of name of test cases
Define the name and framework of a test case by using the method of describe(name, () => {});. The context for each describe should be ensured to be clean.
1 | describe('todo', () => {}) |
Preparation of environment
The preparation should be prior to definition of some cases in before(() => {}).
Remarks: the configuration of file config.js
has been completed in the previous chapter of Deployment of Contract.
1 | var FIBOS = require('fibos.js'); |
As shown above, we created a fibos account and finished contract deployment.
Writing of unit case
Each “it” can be considered as a unit case, respectively testing the four methods in the todo contract.
1 | describe('todo', () => { |
Run the command
1 | fibos-todomvc$ fibos test/index.js |
Display of results
In the test code, we have tested the four methods of adding, deleting, and modifying and finding of the contract, and output the following results (partial):
1 | is_producing_block: 1, tm: 16.138 |
The GitHub source code of this article: in the test
folder under https://github.com/fengluo/fibos-todomvc
Next chapter
👉 【Develop the DApp client】