Writing tests in Solidity

Solidity test code is put in .sol files. Here are the things you need to note about Solidity tests before writing tests using Solidity:

  • Solidity tests shouldn't extend from any contract. This makes your tests as minimal as possible and gives you complete control over the contracts you write.
  • Truffle provides a default assertion library for you, but you can change this library at any time to fit your needs.
  • You should be able to run your Solidity tests against any ethereum client.

To learn how to write tests in Solidity, let's explore the default Solidity test code generated by truffle. This is the code, and it can be found in the TestMetacoin.sol file:

pragma Solidity ^0.4.2; import "truffle/Assert.sol"; import ...

Get Blockchain Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.