【发布时间】:2017-08-07 15:45:56
【问题描述】:
如何针对正在运行的服务器运行 Grails 集成测试?
我在网上搜索过,但建议日期为 2010 年和 Grail 1.3.x...
【问题讨论】:
标签: testing grails grails-3.0 grails-3.1
如何针对正在运行的服务器运行 Grails 集成测试?
我在网上搜索过,但建议日期为 2010 年和 Grail 1.3.x...
【问题讨论】:
标签: testing grails grails-3.0 grails-3.1
Grails 3 集成测试将针对正在运行的服务器运行。您需要定义一个测试环境 application.yml 并将@Integration 注解添加到您的类中。
import grails.test.mixin.integration.Integration
import spock.lang.Specification
@Integration
class LookupServiceIntegrationSpec extends Specification {
def lookupService
def setup() {
}
def cleanup() {
}
void "test database connection"() {
when:
def row = lookupService.testMethod()
then:
println("Row one = "+row.one)
row.one == 1
}
}
这是一个简单的示例服务:
import grails.transaction.Transactional
import groovy.sql.Sql
@Transactional
class LookupService {
def dataSource
def testMethod() {
Sql sql = new Sql(dataSource)
sql.firstRow("SELECT 1 AS one")
}
}
【讨论】:
localhost:8080?
@Integration... 进行注释,但非常感谢您尝试帮助我。 :D 也许我应该概括我的问题:“我怎样才能在运行中的 Grails 服务器上运行任何代码?”。你看到我需要什么了吗?
也许您正在寻找功能测试而不是集成测试。 Grails 3 为功能测试添加了更好的支持。请参阅下面的链接。
【讨论】: