| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (AllTestSuiteTest.groovy)

This example Groovy source code file (AllTestSuiteTest.groovy) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

alltestsuitetest, alltestsuitetest, groovylogtestcase, log, logging, resulting, resulting, script, script, string, string

The Groovy AllTestSuiteTest.groovy source code

package groovy.util

import java.util.logging.Level
import junit.framework.Test

    Testing groovy.util.AllTestSuite.
    The suite() method must properly collect Test files under the given dir and pattern,
    add found files to the log,
    produce a proper TestSuite,
    and wrap Scripts into TestCases.
    @author Dierk Koenig
class AllTestSuiteTest extends GroovyLogTestCase {

    def suite

    void setUp() {
        suite = null

    void testSuiteForThisFileOnly() {
        def result = stringLog(Level.FINEST, 'groovy.util.AllTestSuite') {
            withProps('src/test/groovy/util','AllTestSuiteTest.groovy') {
                suite = AllTestSuite.suite()
        assertTrue result, result.contains('AllTestSuiteTest.groovy')
        assertEquals 1+1, result.count("\n")   // only one entry in the log
        assert suite, 'Resulting suite should not be null'
        assertEquals 2, suite.countTestCases() // the 2 test methods in this file

    void testAddingScriptsThatDoNotInheritFromTestCase() {
        withProps('src/test/groovy/util','suite/*.groovy') {
            suite = AllTestSuite.suite()
        assert suite
        assertEquals 1, suite.countTestCases()
        suite.testAt(0) // call the contained Script to makes sure it is testable

    /** store old System property values for not overriding them accidentally */
    void withProps(dir, pattern, yield) {
        String olddir ='groovy.test.dir'
        String oldpat ='groovy.test.pattern''groovy.test.dir' = dir'groovy.test.pattern' = pattern
        if (olddir)'groovy.test.dir' = olddir
        if (oldpat)'groovy.test.pattern' = oldpat

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy AllTestSuiteTest.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
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.