rwallace
rwallace

Reputation: 33365

What exactly does @Test annotation of Kotlin test methods do?

When writing unit tests in Kotlin, test methods are typically annotated @Test. What exactly does this do?

That is, I understand at the black-box level, the answer is 'it causes them to be recognized by unit testing frameworks like JUnit'. But I'd like to be able to look inside the box (ideally by a more direct route than reading the ~80,000 lines of code comprising the latest version of JUnit). Is it documented anywhere, exactly how the annotation is recognized and what happens when it is?

Upvotes: 0

Views: 568

Answers (1)

ChristophE
ChristophE

Reputation: 873

As a starting point you can read in general about annotation processing in java for example here: https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Processor.html

The concrete class in JUnit4 that is used to read this annotation is https://github.com/junit-team/junit4/blob/master/src/main/java/org/junit/internal/runners/TestClass.java

On a high level: with annotation processing you can do something like

List<TestMethods> methods = getTestMethodsWithAnnotation(@Test) methods.foreach(method -> TestRunner.run(method))

Upvotes: 4

Related Questions