繁体   English   中英

运行集成测试再次运行正在运行的服务器

[英]Run Integration Tests agains a running Server

如何针对正在运行的服务器运行Grails集成测试?

我在网上搜索过,但建议的日期是2010年和Grail 1.3.x ......

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")
    }
}

也许你正在寻找功能测试而不是集成测试。 Grails 3为功能测试增加了更好的支持。 见下面的链接。

Grails 3功能测试

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM