我正在尝试从 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)
我已经看到这个关于如何配置自动下载 ChromeDriver 的请求请求。但是,我在测试中将其实例化如下:
def "signup as a new user"() {
given:
def server = SimpleSmtpServer.start(1025)
driver = new ChromeDriver()
有没有更好的方法来实例化 ChromeDriver 以进行个人测试?