gpt4 book ai didi

testing - 从 Grails 2.0.3 升级到 2.2.1 : Tests Failing

转载 作者:行者123 更新时间:2023-11-28 20:15:54 25 4
gpt4 key购买 nike

我正在尝试从 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?

最佳答案

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

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

如果您运行 Chrome 仅用于一项测试,请尝试在命令中添加 -Dgeb.env=chrome

关于testing - 从 Grails 2.0.3 升级到 2.2.1 : Tests Failing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15413701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com