Frage

I remember having seen something like:

/**
 * ("world") -> "hello world"
 * ("") -> "hello "
 */
public static myFunc(in) {
  return "hello " + in;
}

So you can place trivial tests directly in the documentation block of a function. Your test framework finds these tests and executes them.

But I can't remember whether I saw this in Java, Python, PHP or JavaScript. Do you know any tools in any language who do this? Is there a special name for this thing?

I already found it in groovy.

War es hilfreich?

Lösung

In python it is called doctest:

The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top