groovy.util
Class GroovyTestCase

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: 11086 $

Field Summary
 int counter
           
 Logger log
           
 ThreadLocal notYetImplementedFlag
           
 boolean useAgileDoxNaming
           
 
Constructor Summary
GroovyTestCase()
           
 
Method Summary
void assertArrayEquals(def expected, def value)
           Asserts that the arrays are equivalent and contain the same values
void assertContains(char expected, def array)
           Asserts that the array of characters contains a given char
void assertContains(int expected, def 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)
          
void assertInspect(Object value, String expected)
           Asserts that the value of inspect() on the given object matches the given text string
void assertLength(int length, def array)
           Asserts that the array of characters has a given length
void assertLength(int length, def array)
           Asserts that the array of ints has a given length
void assertLength(int length, def array)
           Asserts that the array of objects has a given length
void assertScript(String script)
           Asserts that the script runs without any exceptions
void assertToString(Object value, String expected)
           Asserts that the value of toString() on the given object matches the given text string
static Method findRunningJUnitTestMethod(Class caller)
           From JUnit.
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!)
String getTestClassName()
          
static boolean isPublicTestMethod(Method method)
           From Junit.
static boolean notYetImplemented(TestCase caller)
          
boolean notYetImplemented()
           Convenience method for subclasses of GroovyTestCase, identical to
 GroovyTestCase.notYetImplemented(this); 
.
String shouldFail(Closure code)
           Asserts that the given code closure fails when it is evaluated
String shouldFail(Class clazz, Closure code)
           Asserts that the given code closure fails when it is evaluated and that a particular exception is thrown.
String shouldFailWithCause(Class clazz, Closure code)
          
Throwable unwrap(GroovyRuntimeException gre)
          
 

Constructor Detail

GroovyTestCase

public GroovyTestCase()


Method Detail

assertArrayEquals

void assertArrayEquals(def expected, def value)
Asserts that the arrays are equivalent and contain the same values
param:
expected
param:
value


assertContains

void assertContains(char expected, def array)
Asserts that the array of characters contains a given char
param:
expected expected character to be found
param:
array the array


assertContains

void assertContains(int expected, def 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

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

void assertLength(int length, def array)
Asserts that the array of characters has a given length
param:
length expected length
param:
array the array


assertLength

void assertLength(int length, def array)
Asserts that the array of ints has a given length
param:
length expected length
param:
array the array


assertLength

void assertLength(int length, def array)
Asserts that the array of objects has a given length
param:
length expected length
param:
array the array


assertScript

void assertScript(String script)
Asserts that the script runs without any exceptions
param:
script the script that should pass without any exception thrown


assertToString

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


findRunningJUnitTestMethod

static Method findRunningJUnitTestMethod(Class caller)
From JUnit. Finds from the call stack the active running JUnit test case
return:
the test case method
throws:
RuntimeException if no method could be found.


fixEOLs

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

String getTestClassName()


isPublicTestMethod

static boolean isPublicTestMethod(Method method)
From Junit. Test if the method is a junit test.
param:
method the method
return:
true if this is a junit test.


notYetImplemented

public static boolean notYetImplemented(TestCase caller)


notYetImplemented

public boolean notYetImplemented()
Convenience method for subclasses of GroovyTestCase, identical to
 GroovyTestCase.notYetImplemented(this); 
.
see:
#notYetImplemented(junit.framework.TestCase)
return:
when not itself already in the call stack


shouldFail

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

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

String shouldFailWithCause(Class clazz, Closure code)


unwrap

Throwable unwrap(GroovyRuntimeException gre)