2016-07-26 3 views

答えて

0

Spock Manual, chapter "Extensions"は、sysenvosjvmのようにバインドされた変数を使用する方法について説明します。しかし、基本的にGroovyクロージャーをそこに置くことができます。

テストを実行しているときにコマンドラインで環境変数またはシステムプロパティを指定した場合は、それらにアクセスするためにenvまたはsysを使用できます。 spock.properties

ファイル:あなたが絶対ファイルからプロパティを読みたい場合はしかし、ちょうどこのようなヘルパークラスを使用し

は、おそらくあなたがSRC下のどこかにファイルを入れたいです/テスト/リソース Mavenでビルドする場合。プロパティを読み取り

spock.skip.slow=true 

ヘルパークラスは、ファイル:

import spock.lang.IgnoreIf 
import spock.lang.Specification 
import spock.util.environment.OperatingSystem 

class IgnoreIfTest extends Specification { 
    @IgnoreIf({ SpockSettings.SKIP_SLOW_TESTS }) 
    def "slow test"() { 
     expect: 
     true 
    } 

    def "quick test"() { 
     expect: 
     true 
    } 

    @IgnoreIf({ os.family != OperatingSystem.Family.WINDOWS }) 
    def "Windows test"() { 
     expect: 
     true 
    } 

    @IgnoreIf({ !jvm.isJava8Compatible() }) 
    def "needs Java 8"() { 
     expect: 
     true 
    } 

    @IgnoreIf({ env["USERNAME"] != "kriegaex" }) 
    def "user-specific"() { 
     expect: 
     true 
    } 
} 

class SpockSettings { 
    public static final boolean SKIP_SLOW_TESTS = ignoreLongRunning(); 

    public static boolean ignoreLongRunning() { 
     def properties = new Properties() 
     def inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("spock.properties") 
     properties.load(inputStream) 
     inputStream.close() 
     //properties.list(System.out) 
     Boolean.valueOf(properties["spock.skip.slow"]) 
    } 
} 

テストヘルパークラスを使用して

関連する問題