Using @MockBean gets "Cannot stop service..." Error - SpringBootTest


#1

Am having issues when using @MockBean in conjunction with Camunda.
Getting Error:
Cannot stop service org.camunda.bpm.platform.process-engine:type=default: no such service registered: service is null.
Single Tests work OK but will get this Error when running full Test Suite.
Using “@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)” in Tests.

This is demonstrated in the following Repository link:


#2

we had an issue with MockBean in the past, please check if https://github.com/camunda/camunda-bpm-spring-boot-starter/issues/208 sounds familiar to your problem. In that case, Oliver found this solution:

Within your tests you are trying to register multiple beans within the same application context. This is wrong usage of spring (testing). This is not related to the extension.

Hints:

use different contexts/configurations (one to use @Autowired private IntService intService; and one to use

@MockBean private IntService intService;).

or

dirty the context, for example:

@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext
public class IntServiceMockTest {

  @MockBean
  private IntService intService;
...

Does that help you?


#3

hmm not sure if this is a similar problem.
I dont understand what you mean by the first hint, we’ve tried the second hint but this doesnt seem to work either.

Are you able to run the test suite on the attached respitory to help understand and possible resolve the issue?


#4

No, I haven’t checked your module so far, just posted the first thing that came to my mind … will have a look at it.


#5

wondered if you had a chance to look into this yet? :smile:


#6

Had it run on my machine, also switched to latest extension and spring boot version … same result as you had …

no further ideas so far, sorry.