Inject Services in Grails Unit Test

前端 未结 2 816
北恋
北恋 2021-02-14 12:38

I know that you can simply inject a service in unit test method using:

defineBeans {
   someService(SomeService)
}

But when I need to inject se

2条回答
  •  北海茫月
    2021-02-14 13:20

    To use spring beans in a unit test you need to do the following:

    • Include all the services and other beans the test depends on in the defineBeans closure.
    • Set the autowire property to true for beans that need to have other beans injected.

    For example:

    defineBeans {
        someService(SomeService) { bean ->
            bean.autowire = true
        }
        some2Service(Some2Service)
    }
    

提交回复
热议问题