Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top