mardi 26 novembre 2019

Kotlintest extensions providing information back to the test

JUnit 5 has a neat extensions functionality which is not compatible with kotlintest even if it runs on JUnit framework. While the simple use cases in which we just need to log something can be handled by the TestListener, we cannot handle more advanced cases. In particular, how to interact with the extension? Ideally, I would like to get a hold of the extension so I could query it.

In JUnit5 it would be (one of the options anyway)

@ExtendWith(MyExtension.class)
class Something() {

 @MyAnnotation
 MyType myType;

 @Test
 void doSomething() {
    myType.doSomething();
 }

}

In JUnit4 it would be even simpler

@Rule
MyRule myRule;

@Test
void fun() {
  myRule.something();
}

Of course, there is a SpringExtension but it does the reflective instantiation of the class. Is there any way to do it easier?

Aucun commentaire:

Enregistrer un commentaire