mardi 18 septembre 2018

Load all beans in spring boot while testing

I am running a spring server and seeding some data by defining a component which implements the ApplicationRunner

@Component
class Seeder : ApplicationRunner {
    override fun run(args: ApplicationArguments?) {
      // seeds the data
    }
}

My test configuration looks something like this

@ExtendWith(SpringExtension::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
    classes = [MainApplication::class])
class ApiTest {

  @MockBean
  private lateinit var repo: testRepository

  @Test fun `check init`() {
    println(repo.count())
  }
}

The seeder component is not getting loaded when I run the test but it does get fired when I try to run the application manually. What am I missing ?

Aucun commentaire:

Enregistrer un commentaire