-
March 16th, 2012, 07:52 AM
#1
GRAILS Unit Testing
I am very new to GRAILS and I am trying to understand some code for unit testing. I haven't used unit testing before and I only know a little C# and php.
Could someone explain what assertEquals 1 is doing and what it is for?
Here is some example code I was using:
import grails.test.*
class BaseTests extends GrailsUnitTestCase {
protected void setUp() {
super.setUp()
mockDomain(Base)
}
protected void tearDown() {
super.tearDown()
}
void testConstraints() {
Base base = new Base(name: 'Standard', cost:5)
assertTrue base.validate()
base.name = ' '
assertFalse base.validate()
assertEquals 1, base.errors.errorCount
assertEquals 'blank', base.errors['name']
}
}
I just am having trouble understanding the last two lines of code and what they are doing. I can't find an explanation anywhere so any help is appreciated.
Thanks!
-
March 16th, 2012, 10:44 AM
#2
Re: GRAILS Unit Testing
I don't know GRAILS at all but I would guess that:
'assertEquals 1, base.errors.errorCount' is testing that base.errors.errorCount is equal to 1.
'assertEquals 'blank', base.errors['name']' is testing that base.errors['name'] is equal to 'blank'.
In both cases if the assert statement is not true the text case will fail and you will be given some indication of that - don't know how as I've never used it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|