grails - Unit testing session variable in controller with spock -
I'm trying to test that a session variable is installed in a controller in a method that has a Grails controller Using unit testing in but it is complaining about establishing a readable property:
Can not set asset to read: Session for class: MyController I have something like this:
class MyController {def settion session = {session.var1 = "Hello world!" }} And this will be my test:
class MyControllerUnitTest controller SEPEC {def "My test with session" () {when: controller.settingSession () Then: controller.session.var1 == "Hello world!" }} I am a guest that I should probably write an integration test but I would like to know if there is any possibility of doing this unit in the test.
The following tests will pass along Grails 2.1.0
A controller:
// Gilles-App / Controller / Demo / Mac Controller. Groovy package demo class MyController {def settingSession () {session.band = 'King Crimson'}} One unit test:
// test / unit / demo / myControllerTests.groovy package demo import grails.test.mixin. * Import org.junit. * @TestFor (MyController) class MyControllerTests {zero test} session () {controller. SettingSession () session.band == 'King Crimson insists'}} If you are using Spock:
// Test / unit / demo / MyControllerSpec.groovy package demo import grails.test.mixin * import spock.lang.Specification @TestFor (MyController) class Provides MyControllerSpec Specification {Zero 'Test Session' () {When: Controller. Setting session () then: session.band == 'King Crimson'}}
Comments
Post a Comment