Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

AEM cloud: how to get hold of the real OSGi config to test a service instead of a mock one?

Avatar

Level 9

We want to unit test a service.  We want this service to have the right config for the right environment (dev, prod or stage).  

 

We can use a dummy config like this:

MyServiceImpl.Config config2 = mock(MyServiceImpl.Config.class);
context.registerInjectActivateService(new MyServiceImpl(config2));

Is it possible to pull in the same config as a running environment would, instead of creating a dummy one?

2 Replies

Avatar

Employee Advisor

Hi @TB3dock ,

Junits are tested during the maven build as it need not to be connected to an instance while building. Adding to the same reason, we use stubbing [when().thenReturn()] to control the output of each method call.

The other way would be to use a dummy config which you have mentioned, you can create multiple dummy configs for dev, stage & prod and write test cases accordingly.


Best Regards,

Milind

Avatar

Level 9

We had the issue that adobe changed the production version  (without warning) of java to one with a known p1 bug which broke all http2 calls to our backend, and all our sites were down for 4 days.    Adobes "answer" to this was that it was our fault they broke our environments because we didnt have tests for this.  But now you are telling us, we cant call any actual services, we can only call mocks with no data, no proper configs or connections, which is pretty useless.  We were hoping to have at lease one API call to our backend as part of the tests run by adobe. If we cant do this, then adobe will be risking causing us major downtime next time they "upgrade" prod without warning.  If there is instance to test against, I would suggest tests are of little value.