[Ethereum] the reason for writing truffle tests in .sol and .js files

testingtruffle

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?

Best Answer

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.

Related Topic