从Grails 2.0.3升级到2.2.1:测试失败

时间:2013-03-14 15:39:48

标签: testing grails upgrade geb

我正在尝试从Grails 2.0.3升级到2.2.1。我有两个问题:1)单元测试失败,2)集成测试失败。

第一个问题是缺少方法异常:

| Failure:  testSendingBlankDirectionsAreOK(happytrails.RouteControllerTests)
|  java.lang.reflect.InvocationTargetException
    at happytrails.RouteControllerTests.testSendingBlankDirectionsAreOK(RouteControllerTests.groovy:163)
Caused by: org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: happytrails.Route.addToDirections() is applicable for argument types: (happytrails.Direction) values: [null]
Possible solutions: getDirections()

测试如下:

void testSendingBlankDirectionsAreOK() {
    populateValidParams(params)

    params['directions[0].sortNumber'] = ''
    params['directions[0].instruction'] = ''

    def route = new Route(params)
    assert route.save() != null
    params.id = route.id

    controller.update()

    println route.errors

    assert response.redirectedUrl == "/route/show/$route.id"
    assert flash.message != null
}

第二个问题似乎是由Geb引起的,它试图使用Chrome驱动程序。

| Running 11 spock tests... 6 of 11
| Failure:  signup as a new user(happytrails.AuthenticatedUserSpec)
|  org.openqa.selenium.WebDriverException: Unable to either launch or connect to Chrome. Please check that ChromeDriver is up-to-date. Using Chrome binary at: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 45.66 seconds
Build info: version: '2.27.0', revision: '18259', time: '2012-12-05 11:30:53'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.2', java.version: '1.7.0_04'
Driver info: org.openqa.selenium.chrome.ChromeDriver
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:533)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:161)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
    at happytrails.AuthenticatedUserSpec.signup as a new user(AuthenticatedUserSpec.groovy:25)

我见过this pull request有关如何配置自动下载ChromeDriver的内容。但是,我在我的测试中将其实例化如下:

def "signup as a new user"() {
    given:
    def server = SimpleSmtpServer.start(1025)
    driver = new ChromeDriver()

有没有更好的方法来为单个测试实例化ChromeDriver?

1 个答案:

答案 0 :(得分:0)

关于您的单元测试,在Grails 2.2.x上,您需要模拟与测试相关的所有域类。这在Release Notes

中有解释

对于您的功能测试,如果您使用其他驱动程序,它有效吗?此外,对于浏览器的不同版本,还存在selenium的特定版本。例如,我有FF 18.0,唯一适用于此的硒版本是2.29,因此您可以检查您的铬和硒的兼容性。

如果您只为一次测试运行Chrome,请尝试在命令中添加-Dgeb.env=chrome