Testing a contract
Now we can write unit tests for our contract functions. We will focus on testing the Node.js-based TradeContract
and use the Mocha testing framework (https://mochajs.org/) with the Chai assertion library (https://www.chaijs.com/), which allows us to write tests as English sentences, and the Sinon mocking library (https://sinonjs.org/), which allows us to create stubs of objects.
Note that by convention, the test suite file containing unit tests ends with the suffix .spec.ts
; therefore, our test suite file will be named trade-contract.spec.ts
and placed in the same directory as our contract file. The output of the test is written into the standard output, where it can be inspected in the terminal after execution.
For testing of Java-based contracts, you can use JUnit (https://junit.org/).
The JUnit tests of ExportLicenseContract
are placed in the file ExportLicenseContractTest.java
located in folder $GOPATH/src/trade-contracts/v1/exportLicense...