is there a less bloated way to test constraints in grails?

Posted by egervari on Stack Overflow See other posts from Stack Overflow or by egervari
Published on 2010-05-24T19:00:20Z Indexed on 2010/05/24 19:31 UTC
Read the original article Hit count: 216

Filed under:
|
|

Is there a less bloated way to test constraints? It seems to me that this is too much code to test constraints.

class BlogPostTests extends GrailsUnitTestCase {

    protected void setUp() {
        super.setUp()
        mockDomain BlogPost
    }

    void testConstraints() {
        BlogPost blogPost = new BlogPost(title: "", text: "")
        assertFalse blogPost.validate()
        assertEquals 2, blogPost.errors.getErrorCount()
        assertEquals "blank", blogPost.errors.getFieldError("title").getCode()
        assertEquals "blank", blogPost.errors.getFieldError("text").getCode()

        blogPost = new BlogPost(title: "title", text: ObjectMother.bigText(2001))
        assertFalse blogPost.validate()
        assertEquals 1, blogPost.errors.getErrorCount()
        assertEquals "maxSize.exceeded", blogPost.errors.getFieldError("text").getCode()
    }
}

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about grails