mocking - Grails integration test doesn't work in test-app but is running correctly when starting alone -


i testing service-class little gorm-action. if run test alone integration-test runs without failures , if run test-app (does not matter if run test-app integration:) test fails , got error message, used domain classes:
"method on class [xx.xx.user] used outside of grails application. if running in context of test using mocking api or bootstrap grails correctly."

since integration-test, dont want mock domain-classes , dont understand error. using grails 2.3.5 correct tomcat , hibernate plugin:

@testfor(entryservice) //@mock([user, task, entry, admin]) class entryservicespec extends specification {      entry entry1     entryservice entryservice     user user     task task     date date      def setup() {         entryservice = new entryservice()         user = user.findbyemail("test@test.de")         task = task.findbyname("something_inserted")         date = new date().cleartime()          entry1 = new entry()         entry1.comment = ""         entry1.effort = 23 bigdecimal         entry1.user = user         entry1.bookedtask = task         entry1.bookedcosts = 300 bigdecimal         entry1.entryday = new date().cleartime()         entry1.save(flush: true)     }      def cleanup() {         if(entry1 != null && entry1.id != null) {             entry1.delete()         }     }      void "wished effort shall added exceeding 24-hours day-constraints"() {         expect: "user has 23h erfforts, wants add 2 more hours, should exceed"             entryservice.isentryeffortexceedinghoursconstraintsperday(user, date, new bigdecimal(2)) == true     }      void "wished effort shall added not exceeding 24-hours day-constraints"() {         expect: "user has 23h erfforts, wants add 1 more hours, should not exceed"             entryservice.isentryeffortexceedinghoursconstraintsperday(user, date, new bigdecimal(1)) == false     }      void "null parameter should leed return false"() {         expect: "user null, method should return false"             entryservice.isentryeffortexceedinghoursconstraintsperday(null, date, new bigdecimal(1)) == false          and: "date null, method should return false"             entryservice.isentryeffortexceedinghoursconstraintsperday(user, null, new bigdecimal(1)) == false          and: "wished-effort null, method should return false"             entryservice.isentryeffortexceedinghoursconstraintsperday(user, date, null) == false     } } 

give credit @dmahapatro answered in comments above

you running test unit test , not integration test...

change class signature to:

import grails.test.spock.integrationspec  class entryservicespec extends integrationspec 

notice removed @testfor(entryservice)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -