DEV Community

Discussion on: Use comments to unit test your code.

Collapse
jessekphillips profile image
Jesse Phillips

I think it is unfortunate that the languages haven't learned to make this an integral part of the language.

D made it possible for unittests to become examples, included in the generated documentation. Though uncompiled examples could also be added.

/**
 * Returns the sum of 2 numbers
 */
auto sum(int a, int b) {
  return a + b;
}
///
unittest {
    assert(sum(1, 2) == 3);
}
Collapse
patarapolw profile image
Pacharapol Withayasakpunt

Python's doctest is very standard, and can be integrated with pytest. TIL it comes to JavaScript, though.