I have a controller action that checks a condition and based on the condition’s result, it will set a field to session variable
Controller:
def checkUser={
if(condition: true){
session.user = id
}else{
session.user=null
}
}
Now, in my testcase, if I have to assert on this session’s user value, how do i do it?
I tried it like this, but it did not work:
void testSomething(){
controller.checkUser()
assertNull(session.user)
}
Any idea on how to assert session variable which is being set in the controller?
Make sure your test class extends ControllerUnitTestCase or is using the test Mixin.
CUTC offers several mocks to facilitate Controller testing. Here’s what you’ll do: