How do I specify a custom test directory path in truffle-config.js? My test directory is not present at the same level as truffle-config.js, it is residing in a different directory. Truffle has options to specify custom contracts and migration directory. Similarly, do we have for test directory?


After trying out some things, I found the solution, we have to specify the path of the test directory in the truffle-config.js i.e

module.exports = {
    description: 'Test Configuration',
       networks: {
    test_directory: '../test',
    migrations_directory: 'migrations',

Official Truffle documentation have not mentioned about the custom directory for tests but, this seems to be working.


From the official documentation:

All test files should be located in the ./test directory.


I found this in the source code (Truffle v4.1.16):

  var props = {
    build_directory: function() {
      return path.join(self.working_directory, "build");
    contracts_directory: function() {
      return path.join(self.working_directory, "contracts");
    contracts_build_directory: function() {
      return path.join(self.build_directory, "contracts");
    migrations_directory: function() {
      return path.join(self.working_directory, "migrations");
    test_directory: function() {
      return path.join(self.working_directory, "test");

Which means that you can do it using test_directory (as you've mentioned in a comment).

The documentation that I've linked above is therefore not updated.

  • I have kept all files in the test directory, but the directory is not present at the same level as truffle-config. So how can I specify the path to test directory from truffle-config?
    – FLASH
    May 5 '20 at 7:15
  • @FLASH: The ./ part implies that this folder must reside next to truffle-config.js. May 5 '20 at 7:21
  • Yes, the truffle-config.js and test directory has to be at the same level. May 5 '20 at 8:05
  • I tried specifying test_directory: '../path-of-the-test-directory' in truffle-config.js with the test directory path and it worked. So it seems that we can have a test directory anywhere but, the path needs to be mentioned for the same.
    – FLASH
    May 6 '20 at 4:28
  • @FLASH: Yup, you're right, I checked the source code and it's there. The documentation that I've linked is therefore not updated. May 6 '20 at 4:36

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.