Chapter 10. Unit testing contracts with Mocha

 

This chapter covers

  • Installing and setting up Mocha, a JavaScript unit testing framework
  • Unit testing SimpleCoin with Mocha
  • Writing tests performing negative checks, verifying expected exceptions are thrown
  • Writing tests performing positive checks, verifying logic is executed successfully

In previous chapters, you learned how to develop an Ethereum Dapp by using simple tools that the platform offers. You were able, with some effort, to build an end-to-end Dapp, including a simple web UI and a smart contract layer (including libraries) and to deploy it to the public test network. You wrote Solidity and Web3.js code through Remix or even through plain text editors and launched simple deployment scripts manually, initially on the geth console and later on Node.js.

Although this way of developing a Dapp is acceptable while learning, it isn’t efficient when you start to dedicate more time to developing decentralized applications, especially if you do it professionally. As you learned in the chapter dedicated to the Ethereum ecosystem, various third-party development tools are available to improve code editing to help you unit test your contracts and speed up the development cycle.

10.1. Installing Mocha

 
 

10.2. Setting up SimpleCoin in Mocha

 
 
 
 

10.3. Writing unit tests for SimpleCoin

 
 
 

Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest