common_test.asciidoc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. [[ct]]
  2. == Common Test
  3. Common Test is Erlang's functional testing framework.
  4. Erlang.mk automates the discovery and running of Common
  5. Test suites.
  6. === Writing tests
  7. The http://www.erlang.org/doc/apps/common_test/write_test_chapter.html[Common Test user guide]
  8. is the best place to learn how to write tests. Erlang.mk
  9. requires that file names for test suites end with '_SUITE.erl'
  10. and that the files be located in the '$(TEST_DIR)' directory.
  11. This defaults to 'test/'.
  12. === Configuration
  13. The `CT_OPTS` variable allows you to set extra Common Test
  14. options. Options are documented in the
  15. http://www.erlang.org/doc/apps/common_test/run_test_chapter.html[Common Test user guide].
  16. You can use it to set Common Test hooks, for example:
  17. [source,make]
  18. CT_OPTS = -ct_hooks cowboy_ct_hook
  19. The `CT_SUITES` variable can be used to override what
  20. Common Test suites Erlang.mk will be aware of. It does
  21. not normally need to be set as Erlang.mk will find the
  22. test suites automatically.
  23. The name of the suite is the part before `_SUITE.erl`.
  24. If the file is named 'http_SUITE.erl', the test suite
  25. is `http`:
  26. [source,make]
  27. CT_SUITES = http ws
  28. === Usage
  29. To run all tests (including Common Test):
  30. [source,bash]
  31. $ make tests
  32. To run all tests and static checks (including Common Test):
  33. [source,bash]
  34. $ make check
  35. You can also run Common Test separately:
  36. [source,bash]
  37. $ make ct
  38. Erlang.mk will create targets for all test suites it finds.
  39. If you have a file named 'test/http_SUITE.erl', then the
  40. target `ct-http` will run that specific test suite:
  41. [source,bash]
  42. $ make ct-http
  43. Erlang.mk provides a convenient way to run a specific
  44. group or a specific test case within a specific group,
  45. using the variable `t`. Note that this only applies to
  46. suite-specific targets, like the `ct-http` example above.
  47. To run all tests from the `http_compress` group in the
  48. `http_SUITE` test suite, write:
  49. [source,bash]
  50. $ make ct-http t=http_compress
  51. Similarly, to run a specific test case in that group:
  52. [source,bash]
  53. $ make ct-http t=http_compress:headers_dupe
  54. To do the same against a multi-application repository,
  55. you can use the `-C` option:
  56. [source,bash]
  57. $ make -C apps/my_app ct-http t=my_group:my_case
  58. Note that this also applies to dependencies. When using Cowboy
  59. as a dependency, you can run the following directly:
  60. [source,bash]
  61. $ make -C deps/cowboy ct-http t=http_compress
  62. Finally, xref:coverage[code coverage] is available,
  63. but covered in its own chapter.