Unit testing with dapp should feel familiar to anyone who has used a test harness in other high-level programming languages. The DSTest parent class provides assertion functions for validating correctness and events for logging data in the console. These are detailed in the API reference guide below. Other than those functions, there are only a few basic conventions that you will need to learn to run your tests:

Any functions that begin with the prefix test will be evaluated for correctness. In the general case, a testcase is considered correct if it doesn’t throw an exception. Additionally, functions that begin with the prefix testFail are considered correct if they do throw an exception.

Dapp can also help test the correctness of an emitted sequence of events. To use this feature, call the expectEventsExact function with the address of the contract you are testing. Then you simply emit the events that you’re expecting, and dapp will ensure that they are called by your contract in the same order and with the same data. This means that in your source code, you will need to split out your event definitions into their own contracts so that your test contracts can inherit from them and have access to the right events.