CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2009
    Posts
    2

    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!

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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 code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured