# Running Tests and Analyzing Results ## Using the Common Test Framework The `Common Test` framework provides a high-level operator interface for testing, providing the following features: - Automatic compilation of test suites (and help modules) - Creation of extra HTML pages for improved overview. - Single-command interface for running all available tests - Handling of configuration files specifying data related to the System Under Test (SUT) (and any other variable data) - Mode for running multiple independent test sessions in parallel with central control and configuration ## Automatic Compilation of Test Suites and Help Modules When `Common Test` starts, it automatically attempts to compile any suites included in the specified tests. If particular suites are specified, only those suites are compiled. If a particular test object directory is specified (meaning all suites in this directory are to be part of the test), `Common Test` runs function `make:all/1` in the directory to compile the suites. If compilation fails for one or more suites, the test run stops immediately if some suites fail to compile. This behavior can however be modified with the `ct_run` flag `-abort_if_missing_suites`, or the `ct:run_test/1` option `{abort_if_missing_suites,TrueOrFalse}`.Option `abort_if_missing_suites` is set to `true` by default. If `abort_if_missing_suites` is set to `false`, the compilation errors are printed to tty and the operator is asked if the test run is to proceed without the missing suites, or be aborted. If the operator chooses to proceed, the tests having missing suites are noted in the HTML log. If `Common Test` is unable to prompt the user after compilation failure (if `Common Test` does not control `stdin`), the test run proceeds automatically without the missing suites. Any help module (that is, regular Erlang module with name not ending with "\_SUITE") that resides in the same test object directory as a suite, which is part of the test, is also automatically compiled. A help module is not mistaken for a test suite (unless it has a "\_SUITE" name). All help modules in a particular test object directory are compiled, no matter if all or only particular suites in the directory are part of the test. If test suites or help modules include header files stored in other locations than the test directory, these include directories can be specified by using flag `-include` with [`ct_run`](ct_run_cmd.md), or option `include` with `ct:run_test/1`. Also, an include path can be specified with an OS environment variable, `CT_INCLUDE_PATH`. _Example (bash):_ `$ export CT_INCLUDE_PATH=~testuser/common_suite_files/include:~testuser/common_lib_files/include` `Common Test` passes all include directories (specified either with flag/option `include`, or variable `CT_INCLUDE_PATH` , or both, to the compiler. Include directories can also be specified in test specifications, see [Test Specifications](run_test_chapter.md#test_specifications). If the user wants to run all test suites for a test object (or an OTP application) by specifying only the top directory (for example, with start flag/option `dir`), `Common Test` primarily looks for test suite modules in a subdirectory named `test`. If this subdirectory does not exist, the specified top directory is assumed to be the test directory, and test suites are read from there instead. To disable the automatic compilation feature, use flag `-no_auto_compile` with `ct_run`, or option `{auto_compile,false}` with `ct:run_test/1`. With automatic compilation disabled, the user is responsible for compiling the test suite modules (and any help modules) before the test run. If the modules cannot be loaded from the local file system during startup of `Common Test`, the user must preload the modules before starting the test. `Common Test` only verifies that the specified test suites exist (that is, that they are, or can be, loaded). This is useful, for example, if the test suites are transferred and loaded as binaries through RPC from a remote node. [](){: #ct_run } ## Running Tests from the OS Command Line The [`ct_run`](ct_run_cmd.md) program can be used for running tests from the OS command line, for example, as follows: - `ct_run -config -dir ` - `ct_run -config -suite ` - `ct_run -userconfig -suite ` - `ct_run -config -suite -group -case ` _Examples:_ ```text $ ct_run -config $CFGS/sys1.cfg $CFGS/sys2.cfg -dir $SYS1_TEST $SYS2_TEST $ ct_run -userconfig ct_config_xml $CFGS/sys1.xml $CFGS/sys2.xml -dir $SYS1_TEST $SYS2_TEST $ ct_run -suite $SYS1_TEST/setup_SUITE $SYS2_TEST/config_SUITE $ ct_run -suite $SYS1_TEST/setup_SUITE -case start stop $ ct_run -suite $SYS1_TEST/setup_SUITE -group installation -case start stop ``` The flags `dir`, `suite`, and `group/case` can be combined. For example, to run `x_SUITE` and `y_SUITE` in directory `testdir`, as follows: ```text $ ct_run -dir ./testdir -suite x_SUITE y_SUITE ``` This has the same effect as the following: ```text $ ct_run -suite ./testdir/x_SUITE ./testdir/y_SUITE ``` For details, see [Test Case Group Execution](run_test_chapter.md#group_execution). The following flags can also be used with [`ct_run`](ct_run_cmd.md): - **`-help`** - Lists all available start flags. - **`-logdir `** - Specifies where the HTML log files are to be written. - **`-label `** - Associates the test run with a name that gets printed in the overview HTML log files. - **`-refresh_logs`** - Refreshes the top-level HTML index files. - **`-shell`** - Starts interactive shell mode (described later). - **`-step [step_opts]`** - Steps through test cases using the Erlang Debugger (described later). - **`-spec `** - Uses test specification as input (described later). - **`-allow_user_terms`** - Allows user-specific terms in a test specification (described later). - **`-silent_connections [conn_types]`** - , tells `Common Test` to suppress printouts for specified connections (described later). - **`-stylesheet `** - Points out a user HTML style sheet (described later). - **`-cover `** - To perform code coverage test (see [Code Coverage Analysis](cover_chapter.md#cover)). - **`-cover_stop `** - To specify if the `cover` tool is to be stopped after the test is completed (see [Code Coverage Analysis](cover_chapter.md#cover_stop)). - **`-event_handler `** - To install [event handlers](event_handler_chapter.md#event_handling). - **`-event_handler_init `** - To install [event handlers](event_handler_chapter.md#event_handling) including start arguments. - **`-ct_hooks `** - To install [Common Test Hooks](ct_hooks_chapter.md#installing) including start arguments. - **`-ct_hooks_order [test|config]`** - To modify [Common Test Hooks](ct_hooks_chapter.md#installing) execution order. - **`-enable_builtin_hooks `** - To enable or disable [Built-in Common Test Hooks](ct_hooks_chapter.md#builtin_cths). Default is `true`. - **`-include`** - Specifies include directories (described earlier). - **`-no_auto_compile`** - Disables the automatic test suite compilation feature (described earlier). - **`-abort_if_missing_suites`** - Aborts the test run if one or more suites fail to compile (described earlier). - **`-multiply_timetraps `** - Extends [timetrap time-out](write_test_chapter.md#timetraps) values. - **`-scale_timetraps `** - Enables automatic [timetrap time-out](write_test_chapter.md#timetraps) scaling. - **`-repeat `** - Tells `Common Test` to repeat the tests `n` times (described later). - **`-duration