Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Modifiers | Name | Description |
---|---|---|
static String |
TEST_SCRIPT_NAME_PREFIX |
Type | Name and description |
---|---|
static void |
assertScript(String script) Asserts that the script runs without any exceptions |
protected static String |
genericScriptName() @return a generic script name to be used by GroovyShell#evaluate calls. |
static boolean |
notYetImplemented(Object caller) |
static Throwable |
shouldFail(Closure code) Asserts that the given code closure fails when it is evaluated |
static Throwable |
shouldFail(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 Throwable |
shouldFail(Class clazz, String script) Asserts that the given script fails when it is evaluated and that a particular type of exception is thrown. |
static Throwable |
shouldFail(String script) Asserts that the given script fails when it is evaluated |
static Throwable |
shouldFailWithCause(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. |
Asserts that the script runs without any exceptions
script
- the script that should pass without any exception thrown
GroovyShell#evaluate
calls.
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 (GroovyTestCase.notYetImplemented(this)) return; ... the real (now failing) unit test }or for JUnit 4
@Test public void XXX() { 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 distribution.
false
when not itself already in the call stackAsserts that the given code closure fails when it is evaluated
code
- the code expected to failAsserts that the given code closure fails when it is evaluated and that a particular type of exception is thrown.
clazz
- the class of the expected exceptioncode
- the closure that should failAsserts that the given script fails when it is evaluated and that a particular type of exception is thrown.
clazz
- the class of the expected exceptionscript
- the script that should failAsserts that the given script fails when it is evaluated
script
- the script expected to failAsserts that the given code closure fails when it is evaluated and that a particular Exception type can be attributed to the cause. The expected exception class is compared recursively with any nested exceptions using getCause() until either a match is found or no more nested exceptions exist.
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 fail