Note pour plus tard. Pour passer de JUnit 4 à JUnit 5 (Jupiter) il faut remplacer l'annotation @RunWith()
par ExtendWith()
.
Évidemment, la classe MockitoJUnitRunner.class
ne pourra pas être passée à ExtendWith()
et il faudra la remplacer par MockitoExtension.class
.
Pour @Chlouchloutte, un tuto simple montrant comment mocker l'objet Context
des routes de JavaLin avec MockK. Mais normalement Mockito en direct devrait aussi faire le café.
Je découvrir un type de packaging que Maven est capable de produire : bundle.
Je copie-colle ci-dessous la définition :
This kind of artifact is an OSGi bundle, typically produced using the maven-bundle-plugin which is part of Apache Felix.
The plugin treats all the classes available to your module (the module's own classes, classes provided by dependencies, other classes on the classpath) as one giant set, then lets you select a subset of those classes to bundle into a jar. It also creates the necessary manifest information to make the artifact an OSGi bundle.
So the artifact you're pulling in by using this dependency is a jar, however it's a jar built by choosing a subset from a much larger set of classes, not just the classes that were defined inside the abdera-core module.
If you have a look at the pom for the abdera project you'll see the maven-bundle-plugin configuration which will give you an idea of which classes have been added to the bundle, and which have been held back.
Bref, l'artifact org.mockito:mockito-core:2.28.2 est maintenant de type bundle.
Le problème : comment initialiser les attributs en @Mock avec TestNG et non JUnit ?
Avec les nouvelles versions de TestNG
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.testng.annotations.BeforeMethod
class MonTest {
@Mock
private var classToMock:ClassToMock
@BeforeMethod
fun setUp() {
MockitoAnnotations.openMocks(this)
}
@Test
fun `my test should check something`() {
// ...
}
}
Avec les anciennes versions de TestNG
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.testng.annotations.BeforeMethod
class MonTest {
@Mock
private var classToMock:ClassToMock
@BeforeMethod
fun setUp() {
MockitoAnnotations.initMocks(this)
}
@Test
fun `my test should check something`() {
// ...
}
}