Grails unit testing not working - NoClassDefFoundError: junit/framework/TestCase

Grails unit testing not working - NoClassDefFoundError: junit/framework/TestCase

我正在 运行根据本书中的说明对我创建的用户域进行测试:"Grails in Action"。这是测试代码

package com.grailsinaction

import grails.test.*

class UserIntegrationTests extends GrailsUnitTestCase {
    void testFirstSaveEver() {
        def user = new User( userId: 'johnny', password: 'secret',
            homepage: 'http://www.johnnylovesblogging.com' )
        assertNotNull user.save()
        assertNotNull user.id

        def foundUser = User.get( user.id )
        assertEquals 'joe', foundUser.userId
    }
}

我 运行 在 grails console 命令之后控制台中的代码,它引发了一个错误:

java.lang.NoClassDefFoundError: junit/framework/TestCase

我的代码没有使用错误消息中提到的 TestCase class。我的依赖有问题吗?

grails 默认带有 Spock 用于测试。这本书谈到了 Junit。您必须更改您的测试用例以扩展 extends Specificationspock.lang.Specification 并相应地更改您的断言等。