vendredi 22 février 2019

Spring Boot testing with different service class

I have a pretty basic question, apologies if it has been asked before. I fear I may not be using the right words, this is my first rodeo with Spring.

I have a RestController declared as such:

@RestController
class TelemetryController {

    @Autowired
    lateinit var service: TelemetryService
    //...
}

with a concrete implementation of TelemetryService as such in our main module:

@Service
class ConcreteTelemetryService : TelemetryService {
   // some production code
}

I then have a service I want to use in my controller during tests (inside our test module:

@Service
class TestingTelemetryService : TelemetryService {
   // some test code using local data
}

Critically, I have do NOT want to use Mockito for this, as the implementation of the tests require very specific setup that is not appropriate for Mockito.

My test is declared as such:

@RunWith(SpringRunner::class)
@SpringBootTest
@AutoConfigureMockMvc
class HowDoInjectServiceExampleTest {

    @Autowired
    lateinit var mockMvc: MockMvc
}

How do I get my TestingTelemetryService inside my controller in this instance?

Aucun commentaire:

Enregistrer un commentaire