Use middleware service in unit test

Hi,

in a unittest I´m trying to get an instance of my middleware service:

service = AppBeans.get(TimelineService.NAME);

but my service isn´t in the context so it ends up in an NoSuchBeanDefinitionException

I don´t understand which config-file is read during the setup of the TestContainer?

Unfortunately is in the sales example the middleware service not used…

Kind regards
Christian Wilkens

Hi Christian,

Your test container should use the same Spring configuration as your runtime container. Look at YourProjectTestContainer constructor, it should set the appPropertiesFiles field value to the list containing your app.properties file which in turn defines the cuba.springContextConfig property with the path to the Spring config file.

Is your service accessible in runtime code? In what part of the unit test you invoke AppBeans.get()? Do you define @ClassRule with your container in the test class?

Hi Konstantin,

I missed the path for my app.properties. Now I changed it to com/company/app.properties and everything works fine (so far).

Thanks!