2016-03-22 11 views
0

applicaiton.ymlファイルのプロパティをgrails 3.0の統合テストにどのように注入するのですか? EXのために統合テストへのプロパティの挿入Grails 3

:私は私のapplicaiton.yml私の統合スポック試験で

---- 
testing: 
    defaults: 
     startUrl: 'http://localhost:8080/' 
---- 

でこのプロパティを持って、私は次のコードを持っている:

class WebpageRolesTestSpec extends Specification { 

    def grailsApplication 
    String LOGIN_URL = grailsApplication.config.getProperty('testing.defaults.startUrl') 

    void "test login screen prompt"() { 
     expect: 
     LOGIN_URL == 'http://localhost:8080/' 
    } 
} 

を私は取得しています例外は次のとおりです。することはできませんヌルオブジェクトのプロパティ 'config'を取得

答えて

1

ホルダーを使用することができます:

import grails.util.Holders 
... 
LOGIN_URL = Holders.config.testing.defaults.startUrl 
... 
+0

完璧!ありがとう! – angryip

1

以下のテストはGrails 3.1.1で動作します。クリーンなアプリケーションが必要だと思います。

import grails.test.mixin.integration.Integration 
import grails.transaction.* 
import spock.lang.* 

@Integration 
@Rollback 
class SampleSpec extends Specification { 
    def grailsApplication 

    void "test something"() { 
     expect:"fix me" 
      grailsApplication.config.getProperty('testing.defaults.startUrl') == 
       'http://localhost:8080/' 
    } 
} 
関連する問題