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?

I 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.

  • Is there any limitations like a Javascript test can't do what Solidity test does and visa versa? Because I can't find how to initialize a struct from a Javascript test. – ferit Jun 7 at 19:13
  • Javascript tests can't cover 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) – Greg Jeanmart Jun 8 at 8:50

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.