I have two Grails Projects in Eclipse. I am referencing one project inside the other with the Configure Build Path setup. Running tests however throws an error java.lang.IllegalStateException: Method on class [com.example.domain.Phone] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
Normally this is fixed with a @Mock (using Mockito) or mockDomain(), but I am not in a unit test so these items are not seen.
How can I test my service layer through an integration test if it cannot see my domain objects that I need to use? These domain objects are separated because of the need to use them across multiple projects.
If your GORM classes are not in the same package as your Application
class then you need to add the ComponentScan
annotation to the Application
class to indicate where you GORM classes are. Example:
@ComponentScan(basePackages=['foo.bar', 'my.company'])
class Application {
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With