mercredi 29 juillet 2015

Spock test is failing on NullPointerException

I am woking on a small grails application and started to use spock as a test framework.

The test is extremely simple at this point:

    @TestFor(TokenService)
class TokenServiceSpec extends Specification {

    TokenService tokenService = new TokenService()

    def setup() {
    }

    def cleanup() {
    }

    def "test generateToken"() {
        expect: 
        tokenService.generateToken(5).length() == 5
    }
}

Where generateToken is an existing public method in TokenService.

When I execute the test I am getting:

Failure:  test generateToken(com.iibs.security.TokenServiceSpec)
|  java.lang.NullPointerException
    at com.iibs.security.TokenServiceSpec.test generateToken(TokenServiceSpec.groovy:22)

When I debug it, I can verify that tokenService is instantiated properly. What could be a reason for this failure?

Thanks for any advice.

Aucun commentaire:

Enregistrer un commentaire