JUnit tests run twice in Grails 2.3 #314

Closed
geb-bot opened this Issue May 22, 2014 · 4 comments

Projects

None yet

2 participants

@geb-bot
geb-bot commented May 22, 2014

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.

@geb-bot
geb-bot commented Jul 22, 2014

Originally posted by Lari Hotari.

Craig, I think it's worth sending a pull request for your change. This is a problem for Grails 2.3+ with Geb plugin versions 0.9.2+ . I just came across the same problem and documented my similar findings in SO http://stackoverflow.com/questions/14404892/geb-firefox-driver-why-my-test-runs-twice/24880397#24880397 .
I would have saved some time if I would have found this issue before digging in to that. :)

@geb-bot
geb-bot commented Jul 22, 2014

Originally posted by Lari Hotari.

The workaround I found for Grails 2.3+ and Geb 0.9.2+ is to run tests with this command:

grails test-app functional:spock

That's just a workaround and it would be better to fix this problem in the Geb plugin.

@geb-bot
geb-bot commented Oct 16, 2014

Originally posted by Marcin Erdmann.

Thanks for investigating Craig and Lari. I was able to reproduce it and shamelessly copied the solution Craig posted which fixed the issue: geb/geb@e223716

@geb-bot
geb-bot commented Oct 16, 2014

Resolved

@geb-bot geb-bot added the Bug label Apr 12, 2015
@erdi erdi was assigned by geb-bot Apr 12, 2015
@geb-bot geb-bot added this to the 0.10.0 milestone Apr 12, 2015
@geb-bot geb-bot closed this Apr 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment