Skip to content

JUnit tests run twice in Grails 2.3 #314

Description

@geb-bot

Originally created by Craig Atkinson.

Originally found by github user 'domurtag' and reported in a Geb sample project craigatk/geb-example#1, JUnit Geb tests are running twice in Grails 2.3 projects. From looking at the test execution, it looks like both Spock and JUnit are running the JUnit tests, resulting in the duplicate execution. The problem can be reproduced with the Github project https://github.com/craigatk/geb-example

I looked into the test class names run by GrailsSpecTestType built in to Grails 2.3 and the one in the Spock plugin, and the one built in to Grails 2.3 runs tests ending in 'Test' and 'Tests', whereas the one in the Spock plugin does not.

GrailsSpecTestType in Grails 2.3

public static final List<String> TEST_SUFFIXES = ["Test", "Tests", "Spec", "Specification"].asImmutable()

GrailsSpecTestType in Spock plugin (Grails 2.2 and below)

public static final TEST_SUFFIXES = ["Spec", "Specification"].asImmutable()

I was able to work around the issue by tweaking the test type registration in _Events.groovy in the Geb-Grails plugin:

eventAllTestsStart = {
    runningTests = true

    tryToLoadTestTypes()

    // The Spock test type in Grails 2.3+ will run JUnit tests as well, so don't register the JUnit test
    // types to avoid running JUnit tests twice when using Grails 2.3+
    if (!softLoadClass(coreSpecTestTypeClassName)) {
        [junit3TestTypeClassName, junit4TestTypeClassName].each { testTypeClassName ->
            def testTypeClass = softLoadClass(testTypeClassName)
            if (testTypeClass) {
                if (!functionalTests.any { it.class == testTypeClass }) {
                    functionalTests << testTypeClass.newInstance('functional', 'functional')
                }
            }
        }
    }
}

If this seems like a reasonable solution, let me know and I'll put together a pull request with the changes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions