Is there a way to run truffle test and not recompile the solidity code each time? It takes a lot of time if i just want to play around with the javascript tests...



If you run truffle test it should only recompile contracts if they were modified.

It is possible that artifacts in build/ directory to be out of sync with contracts that will trigger a compilation of some contracts when running tests (*).

You can try force recompiling all contracts truffle compile --reset. That should start with clean artifacts.

If all else fails, try renaming/removing the build directory, and compiling.

Note (*)

  • Two contracts with the same name will cause continuous recompiling.
  • An incorrect migration scripts can cause Truffle to not update artifacts correctly.
  • This answer seems to answer the OPPOSITE of what was asked. We don't have a problem with compiling, we have a problem with compiling every time tests are run. – JohnAllen Jul 7 '19 at 18:36
  • @JohnAllen The original question is close to two years old and at that time it made sense. The answer reflect my issues at the time. If you have two contracts with the same name then every time you run migrations it will recompile unnecesarily (at the time it will run migrations before running test). Since compile finish without issues it appeared to be a test problem but it was a compile issue. I'm not using Truffle since last year so the answer might be innacurate with recent changes. – Ismael Jul 7 '19 at 21:49

Since January 2020 Truffle suite has option --compile-none

With this option enabled it tests compiled contracts from build/contracts directory.

Here is how it looks like in Truffle v5.1.55:

PS D:\work\ERC20> truffle test  --compile-none                        
Using network 'test'.

Compiling your contracts...
> Everything is up to date, there is nothing to compile.
  • Thank you, this should be marked as the correct answer. – vallard Apr 24 at 6:13

This is a known issue with truffle. As of Nov 2018 and the latest version 4.1.14, there is no out-of-the-box solution. There is a workaround, albeit a bit messy:

Create an empty folder called migrations_null and then run your tests like this:

truffle test --migrations_directory migrations_null
  • It only solves the problem with migration, but then I don't have an access to my contracts. It says that they were not deployed. It will still compile all contracts. – Rob Magier Feb 3 '19 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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