# Test Setup via executing commands

WARNING

This feature is available as part of vREST NG Pro/Enterprise version.

vREST NG provides a field Execute Command in the Details tab to execute a system command. The given command will be executed before the execution of the test case or hook or test suite.

Let's take a practical example. Suppose you want to initialize the MongoDB database state before the execution of the test case or hook or test suite. You may also store your database dumps in the vREST NG Project directory.

Suppose the mongodb restore command is as follows:

mongorestore --db dbname --drop {{$projectDir}}/dumps/dump_1

You may specify the above command in vREST NG Pro edition as shown in the following snapshot.

Note:

  1. If you are receiving the error Error: stderr maxBuffer length exceeded while executing command during test case or hook or test suite execution. In order to resolve this issue, please note that:

    • We have set 1MB of buffer for stdout/stderr. If either stdout/stderr size exceeds this size then you will receive such an error.

    • To resolve this issue, you may redirect the output of stdout/stderr to either /dev/null or to a file.

      mongorestore --db dbname --drop {{$projectDir}}/dumps/dump_1 1> {{$projectDir}}/stdout.log 2> {{$projectDir}}/stderr.log

      In the above command, stdout is redirected to stdout.log file, and stderr is redirected to stderr.log file in your project directory.

  2. Some commands may run indefinitely. To prevent this situation, we have added a default timeout of 3 minutes. However, this option can be customized.