# Test Setup via executing commands

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

Let's take a practical example. Suppose you want to initialize the mongodb database state before the execution of the test case. You may also store your database dumps in the vREST 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 error Error: stderr maxBuffer length exceeded while executing command during test case 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 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 cutomized.