public class GroovyAssert
extends org.junit.Assert
GroovyAssert
contains a set of static assertion and test helper methods and is supposed to be a Groovy
extension of JUnit 4's Assert
class. In case JUnit 3 is the choice, the GroovyTestCase
is meant to be used for writing tests based on TestCase
.
GroovyAssert
methods can either be used by fully qualifying the static method like
groovy.test.GroovyAssert.shouldFail { ... }or by importing the static methods with one ore more static imports
import static groovy.test.GroovyAssert.shouldFail import static groovy.test.GroovyAssert.assertNotNull
GroovyTestCase
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TEST_SCRIPT_NAME_PREFIX |
Constructor and Description |
---|
GroovyAssert() |
Modifier and Type | Method and Description |
---|---|
static void |
assertScript(java.lang.String script)
Asserts that the script runs without any exceptions
|
protected static java.lang.String |
genericScriptName() |
static boolean |
notYetImplemented(java.lang.Object 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. |
static java.lang.Throwable |
shouldFail(java.lang.Class clazz,
Closure code)
Asserts that the given code closure fails when it is evaluated
and that a particular type of exception is thrown.
|
static java.lang.Throwable |
shouldFail(java.lang.Class clazz,
java.lang.String script)
Asserts that the given script fails when it is evaluated
and that a particular type of exception is thrown.
|
static java.lang.Throwable |
shouldFail(Closure code)
Asserts that the given code closure fails when it is evaluated
|
static java.lang.Throwable |
shouldFail(java.lang.String script)
Asserts that the given script fails when it is evaluated
|
static java.lang.Throwable |
shouldFailWithCause(java.lang.Class expectedCause,
Closure code)
Asserts that the given code closure fails when it is evaluated
and that a particular Exception type can be attributed to the cause.
|
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
public static final java.lang.String TEST_SCRIPT_NAME_PREFIX
protected static java.lang.String genericScriptName()
GroovyShell#evaluate
calls.public static void assertScript(java.lang.String script) throws java.lang.Exception
script
- the script that should pass without any exception thrownjava.lang.Exception
public static java.lang.Throwable shouldFail(Closure code)
code
- the code expected to failpublic static java.lang.Throwable shouldFail(java.lang.Class clazz, Closure code)
clazz
- the class of the expected exceptioncode
- the closure that should failpublic static java.lang.Throwable shouldFailWithCause(java.lang.Class expectedCause, Closure code)
If a match is found, the matching exception is returned otherwise the method will fail.
expectedCause
- the class of the expected exceptioncode
- the closure that should failpublic static java.lang.Throwable shouldFail(java.lang.Class clazz, java.lang.String script)
clazz
- the class of the expected exceptionscript
- the script that should failpublic static java.lang.Throwable shouldFail(java.lang.String script)
script
- the script expected to failpublic static boolean notYetImplemented(java.lang.Object 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 for JUnit 3 is:
public void testXXX() { if (GroovyAssert.notYetImplemented(this)) return; ... the real (now failing) unit test }or for JUnit 4
@Test public void XXX() { if (GroovyAssert.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 distribution.
false
when not itself already in the call stack