Using service beans and dependency Injection in Geb Functional Tests

Jim Chertkov

I would like to use a service inside my Geb test to populate some sample data. The sample data is large and complex, and we have already written the code to create it for other controllers and services. Thus a simple mock is out of the question. How can I access this service inside of my Geb test?

Let's assume the name of my Service is testDataService, and looks something like this...

class TestDataService {

    def otherService

    void importData() {
        otherService.getData()
    }
}

Something like the following in Geb would be ideal...

class testSpec extends GebReportingSpec {

    @Shared def testDataService

    def setupSpec() {
        testDataService.importData()
    }

    def test1() {
        ...some test...
    }
}

From what I understand, this should work for a normal integration test. Since it is a functional test, things are quite different and it returns null.

I found a lot of suggestions for the Grails Remote Control plugin, but I would like to know how to do this without it.

A few side notes...

The service class is located inside src/groovy. Though I am sure I wired it in properly as it works as expected when called by other services. Only in functional tests does it not work.

Grails Version: 2.4.5

Geb 0.10.0

Jim Chertkov

For Grails 2.4.5

def testDataService = Holders.applicationContext.getBean("testDataService")

So our testing spec could look like this...

class testSpec extends GebReportingSpec {

    @Shared def testDataService = Holders.applicationContext.getBean("testDataService")

    def setupSpec() {
        testDataService.importData()
    }

    def test1() {
        ...some test...
    }
}

Note that all injected dependencies from other services should be present.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Functional Tests with Grails, Geb & PhantomJS not working

From Dev

Angular service in typescript with dependency injection and minification

From Dev

Using service aliases for dependency injection

From Dev

Best practice for dependency injection in an AngularJS service with TypeScript

From Dev

grails doesn't find geb functional tests

From Dev

Benefits of using dependency injection Spring

From Dev

Using dependency injection on a type="" property

From Dev

Ramifications of using DBContext with Dependency Injection

From Dev

Dependency injection not working inside Grails service

From Dev

Azure service fabric actor dependency injection

From Dev

Ninject Dependency Injection Using Reflection

From Dev

Using Dependency Injection for hardware abstraction

From Dev

Laravel Testing Service Dependency Injection Error

From Dev

Service Fabric Unit Testing and Dependency Injection

From Dev

Passing a service dependency injection for controller testing

From Dev

Using Dependency Injection (Autofac) and avoiding Service Locator pattern

From Dev

Dependency injection and Tests

From Dev

SpringBoot : Testing a service with Constructor Dependency Injection

From Dev

Dependency Injection using together

From Dev

Understanding injection dependency in app and tests in AngularJS

From Dev

Benefits of using dependency injection Spring

From Dev

Error creating beans name with contactService and Injection of autowired dependency failed

From Dev

Spring dependency injection generic service class

From Dev

Service Client Interface for Simple Dependency Injection?

From Dev

Mocking Service dependency in angularjs tests

From Dev

Multiple Dependency Injection using Ninject

From Dev

Passing a service dependency injection for controller testing

From Dev

Dependency injection - trying to avoid using a service locator

From Dev

service dependency injection templated using inheritance

Related Related

  1. 1

    Functional Tests with Grails, Geb & PhantomJS not working

  2. 2

    Angular service in typescript with dependency injection and minification

  3. 3

    Using service aliases for dependency injection

  4. 4

    Best practice for dependency injection in an AngularJS service with TypeScript

  5. 5

    grails doesn't find geb functional tests

  6. 6

    Benefits of using dependency injection Spring

  7. 7

    Using dependency injection on a type="" property

  8. 8

    Ramifications of using DBContext with Dependency Injection

  9. 9

    Dependency injection not working inside Grails service

  10. 10

    Azure service fabric actor dependency injection

  11. 11

    Ninject Dependency Injection Using Reflection

  12. 12

    Using Dependency Injection for hardware abstraction

  13. 13

    Laravel Testing Service Dependency Injection Error

  14. 14

    Service Fabric Unit Testing and Dependency Injection

  15. 15

    Passing a service dependency injection for controller testing

  16. 16

    Using Dependency Injection (Autofac) and avoiding Service Locator pattern

  17. 17

    Dependency injection and Tests

  18. 18

    SpringBoot : Testing a service with Constructor Dependency Injection

  19. 19

    Dependency Injection using together

  20. 20

    Understanding injection dependency in app and tests in AngularJS

  21. 21

    Benefits of using dependency injection Spring

  22. 22

    Error creating beans name with contactService and Injection of autowired dependency failed

  23. 23

    Spring dependency injection generic service class

  24. 24

    Service Client Interface for Simple Dependency Injection?

  25. 25

    Mocking Service dependency in angularjs tests

  26. 26

    Multiple Dependency Injection using Ninject

  27. 27

    Passing a service dependency injection for controller testing

  28. 28

    Dependency injection - trying to avoid using a service locator

  29. 29

    service dependency injection templated using inheritance

HotTag

Archive