Skip to content

Separate tests from code under test in libraries #12393

Closed
@milibopp

Description

@milibopp

The bug reported in #12383 made me aware of the convention that tests in non-std libraries often reside in the same file as the code under test. The privacy issue seen in that bug appears to be an immediate consequence of this convention. The convention also leads to pretty large source files that are imho difficult to handle.

Thus I would like to discuss whether this convention should be changed. To suggest a concrete alternative:

  • Separate the tests into logically coherent units that focus on testing a certain functionality, each of which resides in a separate file
  • Put all these test files into a dedicated test module that is flagged with one #[cfg(test)] in lib.rs; the test module may have substructure depending on the complexity of the library being tested

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions