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

时间:2017-03-16 12:48:56

标签: testing grails grails-3.0 grails-3.1

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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

Grails 3 Functional Tests

相关问题