For one of our modules, tests fail when run by Infinitest because somehow classes that are not in scope are included on the classpath. "Not in scope" means the classes are in other modules/Eclipse projects that are not in the Maven POM deps/Eclipse project configuration scope.
The failing tests are in "module D" with the following root exception:
This is the root exception from the Infinitest console:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [InterfaceX] is defined: expected single matching bean but found 2: [OneFromModuleA, OneFromModuleB]
This error occurs because "module B's" classes are found in the Infinitest run. I don't know why/how, as they are not configured via Maven or Eclipse to be on the classpath: the POM deps are set correctly, and the tests pass from Maven CLI; m2eclipse updates the Eclipse config from the POMs, and the tests pass from the Eclipse launcher as well. Only module A's classes are found with Maven CLI and Eclipse launcher.
This is the module hierarchy:
- Module D depends on modules C and A.
- Module C depends on A; C also depends on B in Maven "test" scope.
- Module B depends on A.
In module C's tests, Spring configuration scans for module B's classes, but not A's.
In module D's tests, Spring configuration scans for module A's classes, but not B's.
I don't know the cause, but does this highlight an Infinitest issue with classpath ordering (e.g. not same as Maven in this scenario?) or what it puts on classpath (e.g. puts all Eclipse projects on classpath vs per the Eclipse config?)?
Workaround: I was able to tweak module D's Spring classpath scanning (to find module A's classes) to make it work for Infinitest. To make this a permanent change and still work with Maven CLI and Eclipse launcher, I would have to tweak some package structure though, so it's not an appreciated workaround.
For those wondering what the modules are...
D is service ITs (integration tests), using prod DAOs/real database tests
C is service prod and unit tests, using B/stubs for tests
B is DAO stubs for unit tests
A is prod DAOs and tests