Groovy 1.7.0

## groovy.util
Class GroovyTestCase

    java.lang.Object
      junit.framework.Assert
          junit.framework.TestCase
              groovy.util.GroovyTestCase

    class GroovyTestCase
    extends TestCase

A default JUnit TestCase in Groovy. This provides a number of helper methods plus avoids the JUnit restriction of requiring all test* methods to be void return type.

author:
  bob mcwhirter

author:
  James Strachan

author:
  Dierk Koenig (the notYetImplemented feature, changes to shouldFail)

version:
  $Revision: 14148 $

Field Summary
`static String` | `TEST_SCRIPT_NAME_PREFIX`
`protected static Logger` | `log`

Constructor Summary
`GroovyTestCase()`

Method Summary
`protected void` | `assertArrayEquals(Object[] expected, Object[] value)` Asserts that the arrays are equivalent and contain the same values
`protected void` | `assertContains(char expected, char[] array)` Asserts that the array of characters contains a given char
`protected void` | `assertContains(int expected, int[] array)` Asserts that the array of ints contains a given int
`static void` | `assertEquals(String message, Object expected, Object actual)`
`static void` | `assertEquals(Object expected, Object actual)`
`static void` | `assertEquals(String expected, String actual)`
`protected void` | `assertInspect(Object value, String expected)` Asserts that the value of inspect() on the given object matches the given text string
`protected void` | `assertLength(int length, char[] array)` Asserts that the array of characters has a given length
`protected void` | `assertLength(int length, int[] array)` Asserts that the array of ints has a given length
`protected void` | `assertLength(int length, Object[] array)` Asserts that the array of objects has a given length
`protected void` | `assertScript(String script)` Asserts that the script runs without any exceptions
`protected void` | `assertToString(Object value, String expected)` Asserts that the value of toString() on the given object matches the given text string
`protected String` | `fixEOLs(String value)` Returns a copy of a string in which all EOLs are \n.
`String` | `getMethodName()`
`String` | `getName()` Overload the getName() method to make the test cases look more like AgileDox (thanks to Joe Walnes for this tip!)
`protected String` | `getTestClassName()`
`static boolean` | `notYetImplemented(TestCase caller)` Runs the calling JUnit test again and fails only if it unexpectedly runs.

`boolean`

`notYetImplemented()`

Convenience method for subclasses of GroovyTestCase, identical to

     GroovyTestCase.notYetImplemented(this);

.

`protected String` | `shouldFail(Closure code)` Asserts that the given code closure fails when it is evaluated
`protected String` | `shouldFail(Class clazz, Closure code)` Asserts that the given code closure fails when it is evaluated and that a particular exception is thrown.
`protected String` | `shouldFailWithCause(Class clazz, Closure code)`

Methods inherited from class TestCase

run, run, toString, getName, setName, countTestCases, runBare, format, fail, fail, assertNotNull, assertNotNull, assertTrue, assertTrue, assertFalse, assertFalse, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNull, assertNull, assertSame, assertSame, assertNotSame, assertNotSame, failSame, failNotSame, failNotEquals, wait, wait, wait, hashCode, getClass, equals, notify, notifyAll

Methods inherited from class Assert

format, fail, fail, assertNotNull, assertNotNull, assertTrue, assertTrue, assertFalse, assertFalse, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNull, assertNull, assertSame, assertSame, assertNotSame, assertNotSame, failSame, failNotSame, failNotEquals, wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll

Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll

Field Detail

### TEST_SCRIPT_NAME_PREFIX

    static final String TEST_SCRIPT_NAME_PREFIX

### log

    protected static Logger log

Constructor Detail

### GroovyTestCase

    public GroovyTestCase()

Method Detail

### assertArrayEquals

    protected void assertArrayEquals(Object[] expected, Object[] value)

  Asserts that the arrays are equivalent and contain the same values
  param:
    expected
  param:
    value

### assertContains

    protected void assertContains(char expected, char[] array)

  Asserts that the array of characters contains a given char
  param:
    expected expected character to be found
  param:
    array the array

### assertContains

    protected void assertContains(int expected, int[] array)

  Asserts that the array of ints contains a given int
  param:
    expected expected int
  param:
    array the array

### assertEquals

    public static void assertEquals(String message, Object expected, Object actual)

### assertEquals

    public static void assertEquals(Object expected, Object actual)

### assertEquals

    public static void assertEquals(String expected, String actual)

### assertInspect

    protected void assertInspect(Object value, String expected)

  Asserts that the value of inspect() on the given object matches the given text string
  param:
    value the object to be output to the console
  param:
    expected the expected String representation

### assertLength

    protected void assertLength(int length, char[] array)

  Asserts that the array of characters has a given length
  param:
    length expected length
  param:
    array the array

### assertLength

    protected void assertLength(int length, int[] array)

  Asserts that the array of ints has a given length
  param:
    length expected length
  param:
    array the array

### assertLength

    protected void assertLength(int length, Object[] array)

  Asserts that the array of objects has a given length
  param:
    length expected length
  param:
    array the array

### assertScript

    protected void assertScript(String script)

  Asserts that the script runs without any exceptions
  param:
    script the script that should pass without any exception thrown

### assertToString

    protected void assertToString(Object value, String expected)

  Asserts that the value of toString() on the given object matches the given text string
  param:
    value the object to be output to the console
  param:
    expected the expected String representation

### fixEOLs

    protected String fixEOLs(String value)

  Returns a copy of a string in which all EOLs are \n.

### getMethodName

    public String getMethodName()

### getName

    public String getName()

  Overload the getName() method to make the test cases look more like AgileDox (thanks to Joe Walnes for this tip!)

### getTestClassName

    protected String getTestClassName()

### notYetImplemented

    public static boolean notYetImplemented(TestCase caller)

  Runs the calling JUnit test again and fails only if it unexpectedly runs.
  This is helpful for tests that don't currently work but should work one day, when the tested functionality has been implemented.
  The right way to use it is:

       public void testXXX() {
         if (GroovyTestCase.notYetImplemented(this)) return;
         ... the real (now failing) unit test
       }

  Idea copied from HtmlUnit (many thanks to Marc Guillemot). Future versions maybe available in the JUnit distro. The purpose of providing a 'static' version is such that you can use the feature even if not subclassing GroovyTestCase.
  return:
    <false> when not itself already in the call stack

### notYetImplemented

    public boolean notYetImplemented()

  Convenience method for subclasses of GroovyTestCase, identical to

       GroovyTestCase.notYetImplemented(this);

  .
  see:
    #notYetImplemented(junit.framework.TestCase)
  return:
    <false> when not itself already in the call stack

### shouldFail

    protected String shouldFail(Closure code)

  Asserts that the given code closure fails when it is evaluated
  param:
    code
  return:
    the message of the thrown Throwable

### shouldFail

    protected String shouldFail(Class clazz, Closure code)

  Asserts that the given code closure fails when it is evaluated and that a particular exception is thrown.
  param:
    clazz the class of the expected exception
  param:
    code the closure that should fail
  return:
    the message of the expected Throwable

### shouldFailWithCause

    protected String shouldFailWithCause(Class clazz, Closure code)

Copyright © 2003-2009 The Codehaus. All rights reserved.