문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top