I can't run a simple Grails functional test using Geb and spock
Asked Answered
C

1

5

I'm asking for help because I don't know what to do with this error... So first of all let me show the stacktrace I get when running my really simple test, what is weird is that my test doesn't seem to be executed ... ? I'm using Grails 2.0

Configuring Spring Security Core ...
... finished configuring Spring Security Core
| Server running. Browse to http://localhost:8080/
| Running 3 functional tests... 1 of 0
| Failure:  initializationError(SecondaryTest)
|  java.lang.Exception: No runnable methods
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:166)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:102)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:344)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:74)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:55)
| Running 3 functional tests... 2 of 0
| Failure:  initializationError(SecondaryTest)
|  java.lang.Exception: The @Rule '_gebReportingSpecTestName' must be public.

    at org.junit.internal.runners.rules.RuleFieldValidator.addError(RuleFieldValidator.java:90)
    at org.junit.internal.runners.rules.RuleFieldValidator.validatePublic(RuleFieldValidator.java:67)
    at org.junit.internal.runners.rules.RuleFieldValidator.validateField(RuleFieldValidator.java:55)
    at org.junit.internal.runners.rules.RuleFieldValidator.validate(RuleFieldValidator.java:50)
    at org.junit.runners.BlockJUnit4ClassRunner.validateFields(BlockJUnit4ClassRunner.java:170)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:344)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:74)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:55)
| Running 3 functional tests... 3 of 0
| Failure:  initializationError(SecondaryTest)
|  java.lang.Exception: The @Rule '_gebReportingSpecTestName' must implement MethodRule or TestRule.
    at org.junit.internal.runners.rules.RuleFieldValidator.addError(RuleFieldValidator.java:90)
    at org.junit.internal.runners.rules.RuleFieldValidator.validateTestRuleOrMethodRule(RuleFieldValidator.java:73)
    at org.junit.internal.runners.rules.RuleFieldValidator.validateField(RuleFieldValidator.java:56)
    at org.junit.internal.runners.rules.RuleFieldValidator.validate(RuleFieldValidator.java:50)
    at org.junit.runners.BlockJUnit4ClassRunner.validateFields(BlockJUnit4ClassRunner.java:170)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:344)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:74)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:55)
| Completed 3 functional tests, 3 failed in 40ms
| Server stopped
| Tests FAILED  - view reports in target/test-reports

And here the groovy files :

SecondaryTest.groovy :

import pages.SignInPage
import geb.spock.GebReportingSpec

class SecondaryTest extends GebReportingSpec {

    String getBaseUrl() { "http://localhost:8080/" }

    File getReportDir() { new File("target/reports/geb") }

    def "I am at siginin page"() {
        when:
        to SignInPage

        then:
        true
    }
}

SignInPage.groovy :

package pages

import geb.Page

class SignInPage extends Page {

    static url = "login/auth"

    static at = { title == "Sign in" }

    static content = {
    }
}

thanks

Coherence answered 24/1, 2012 at 11:34 Comment(0)
R
7

Your test classes must end in Spec not Test. Otherwise Grails won't recognize them as Spock specifications.

Rebellion answered 24/1, 2012 at 12:45 Comment(3)
yes ! Thanks !! the solution was SO obvious I couldn't see it :-)Coherence
Does that mean all my previous unit tests have to be renamed to somethingSpec?Lashonda
Not sure what you mean by "my previous unit tests". Spock test classes have to end in Spec. Note that this question is specific to Grails.Rebellion

© 2022 - 2024 — McMap. All rights reserved.