Inject service to test in unit test

Hi, sry for the newbie question but I could not figure out from documentation how to inject core services in unit tests.

I am using TestConstainer as documented and my test db is getting created and initialised. Now if I want to test a service say DummyService, I am injecting same in my unit test but its null.

I tried using AppBeans also but got no such bean found. Basically I do not want to mock a service but actually call that.

Hi,

injection in Tests does not really work (although i saw it working in Spring boot applications). So you have to use AppBeans.get(MyService.NAME) for it to work…

Here is an example of that (although it is using spock as the testing framework, but the same applies to JUnit): Testing of CUBA applications Part 3 - Services & Integration Tests

You can also see more details in the docs: Middleware Integration Tests - CUBA Platform. Developer’s Manual

Bye
Mario

I have already tried using AppBeans also but got error that no such bean.

I understand that all services are declared as beans in web-spring.xml. Do we need to do something similar for exposing them to tests.

Thanks