What is the reason that tests can be written in both? Is there any distinct advantage to using one over the other?
Or is one in general easy to work with?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI would use the analogy of unit testing vs integration testing to distinguish these two methods.
In my opinion, a Truffle solidity test can be used to cover a small piece of code, basically you will be able to test every single function in your contract in an isolated way (isolated from Web3 essentially).
On the other hand, a Truffle Javascript test (Mocha) demonstrates that different pieces of the system work together. You will be able to test complex scenarios with multiple calls and transactions.
But you can use Javascript Mocha tests for unit testings as well. So I usually prefer Javascript for quick and dirty testing but I would suggest to separate unit-testing (solidity) from integration/functional testing (Javascript) for a big project that involves a team of analysts, developers and testers.
internal
or private
solidity functions (only external
and public
. On the other hand, a solidity test can basically cover all your code but the behavior would be EVM based whilst a JavaScript test reproduce the dApp behavior (analogy of testing an API externally and internally with its implementation, sometime the issue is in the data transport, not in the logic implementation)
Jun 8, 2018 at 8:50
You currently can't test revert in solidity unit tests. Therefore, I find the javascript testing more useful for testing failure cases.
I wrote a blogpost about it.