Modular v0.1.0 Modular.ContractTests View Source

Ensures that public contracts are always covered with tests.

Tests dedicated to contracts serve as living documentation for them. They present a complete sample usage along with prerequisites required for all functions to succeed. As such, they have a great advantage over textual documentation by always being up to date (as long as tests are being run as they should be). Besides that, as entry points for all the code inside their areas, testing them is a reasonable choice anyway for the purpose of validating the integration.

The convention in Elixir is to name specific module's test the same as the module itself, just with the Test suffix and that's exactly the convention that this check verifies.

Usage

Include the check in your .credo.exs:

%{
  configs: [
    %{
      name: "default",
      checks: [
        {Modular.ContractTests, []}
      ]
    }
  ]
}

You can specify the following options:

  • ignore_names - all modules matching this regex (or list of regexes) will be ignored

Notes

  1. This check doesn't measure the test coverage, nor does it ensure that all public functions are indeed tested - it simply makes sure that developer looking for specific contract's test suite will have something to find.

  2. This check ignores modules that have undefined publicity, so it's recommended to complement it with Credo's own Credo.Check.Readability.ModuleDoc in order to ensure that all modules are forced to define it via the @moduledoc attribute.

  3. In current implementation, test module is required even for modules that don't provide any public functions (eg. structs). They should have a corresponding empty test modules for the check to pass. This helps to facilitate tests for structs, exceptions and DSLs that don't define functions but may need testing either way.

Link to this section Summary

Functions

Returns the base priority for the check.

Returns the category for the check.

Callback implementation for Credo.Check.explanation/0.

Callback implementation for Credo.Check.run_on_all?/0.

Link to this section Functions

Returns the base priority for the check.

Callback implementation for Credo.Check.base_priority/0.

Returns the category for the check.

Callback implementation for Credo.Check.category/0.

Callback implementation for Credo.Check.explanation/0.

Link to this function

explanation_for_params() View Source

Callback implementation for Credo.Check.explanation_for_params/0.

Link to this function

format_issue(issue_meta, opts) View Source

Callback implementation for Credo.Check.format_issue/2.

Link to this function

run(source_files, exec, params \\ []) View Source

Callback implementation for Credo.Check.run_on_all?/0.