|
Groovy example source code file (GroovyTestCaseTest.groovy)
The Groovy GroovyTestCaseTest.groovy source codepackage groovy.util /** Testing the notYetImplemented feature of GroovyTestCase. Todo: testing all other features. @author Dierk Koenig */ class GroovyTestCaseTest extends GroovyTestCase { void testNotYetImplementedSubclassUse () { if (notYetImplemented()) return fail 'here the code that is expected to fail' } void testNotYetImplementedStaticUse () { if (GroovyTestCase.notYetImplemented(this)) return fail 'here the code that is expected to fail' } // we cannot test this automatically... // remove the leading x, run the test and see it failing void xtestSubclassFailing() { if (notYetImplemented()) return assert true // passes unexpectedly } void xtestStaticFailing() { if (GroovyTestCase.notYetImplemented(this)) return assert true // passes unexpectedly } // ---------------- void testShouldFailWithMessage() { def msg = shouldFail { throw new RuntimeException('x') } assertEquals 'x', msg } void testShouldFailWithMessageForClass() { def msg = shouldFail(RuntimeException.class) { throw new RuntimeException('x') } println msg assertEquals 'x', msg } void testShouldFail() { shouldFail(MyException) { new Foo().createBar() } } void testShouldFailWithNestedException() { shouldFail(MyException) { new Foo().createBarWithNestedException() } } } class Foo { def createBar() { throw new MyException(null) } def createBarWithNestedException() { throw new MyException(new NullPointerException()) } } class MyException extends RuntimeException { MyException(Throwable cause) { super(cause); } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy GroovyTestCaseTest.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.