Maven | test util classes | Spring: API-located TestHelper component gets Spring loaded at runtime

Hi all, hi @dkayiwa,

I have a @Component-annotated TestHelper class located somewhere in api/src/test/java. I started using this helper to help test REST resources. But since I use it to help test usual controllers as well I face a new issue, later on, at runtime where my module’s activator wouldn’t start because this test helper class is being caught by Spring (and of course the bean can’t be loaded since it uses Mockito and all the usual test libs.)

How can I tell Spring to not attempt to autowire components that are located inside /test? Why is this even happening?

This branch builds fine but the activator will fail to start: commit 1eb6932. This could be tried on Ref App distro 2.2 to 2.6.

This is the error:

Error creating bean with name 'testHelper' defined in URL [jar:file:openmrs/lfhc-distro-dev/.openmrs-lib-cache/visitdocumentsui/visitdocumentsui.jar!/org/openmrs/module/visitdocumentsui/obs/TestHelper.class]

And the full log.

Change this line https://github.com/mekomsolutions/openmrs-module-visitdocumentsui/blob/1eb69322b12d43326ae546f17663102966aa60fb/omod/pom.xml#L322 to this: https://github.com/openmrs/openmrs-module-xforms/blob/master/omod/pom.xml#L134

1 Like

A Maven issue then! As usual: :thumbsup: