4

私は Geb + Spock + jUnit runner + Maven を使用しています私の仕様は次のようなものです:

@Stepwise
class My_Spec extends GebReportingSpec {

    @IgnoreIf({properties['sss'].contains('true')})

    def "testFeature 1" (){
        println ("--> Feature 1 runs")
        given:
        println ("--> mySystemProp is: ${properties['sss']}")
        ...
        when:
        ...
        then:
        ...
    }

    def "testFeature 2" (){
        println ("--> Feature 2 runs")
        when:
        ...
        then:
        ...
    }
}

TestSuite でグループ化する必要があるため、jUnit ランナーで Specs を実行する必要があります。testSuite を実行する前にシステム プロパティを設定する方法を見つけました。jUnit 4.9 - @ClassRule で利用できます。ということで、こちらを使用。このようにして、私の TestSuites は次のようになります。

    @RunWith(Suite.class)
    @Suite.SuiteClasses([
            My_Spec.class,
            My_Spec1.class,
            My_Spec2.class
    ])
    class TestSuite extends Specification {
                @ClassRule
                public static ExternalResource testRule = new ExternalResource(){
                @Override
                        public void before() throws Throwable{
                                System.setProperty('sss', 'true')
                }
        }
}

ただし、@IgnoreIf の動作は機能しません: 追加されたシステム プロパティ 'sss' は表示されませんが、機能メソッドではこのプロパティを使用できます: 機能を実行すると、次の出力が得られます:

Running TestSuite
--> Feature 1 runs
--> mySystemProp is: true
--> Feature 2 runs

これはすべてmaven installで実行します。私のpom.xmlの一部:

        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
            <includes>
                <include>TestSuite.*</include>
            </includes>
            <systemPropertyVariables>

私は何を間違っていますか?すべてが正しければ、jUnit TestSuite で定義する必要がある spock の @IgnoreIf と props で動作させるにはどうすればよいですか? (jUnit の @Categories の使用を提案しないでください。)

ありがとう。

4

1 に答える 1

0

properties['sss']に渡されたクロージャ内から正しいメソッド呼び出しに解決されますか@IgnoreIf? 私は過去に、特にシステムの小道具を解決するときに静的インポートでこの種の簡潔な式を使用しようとして、あまりにもグルーヴィーになろうとすることに悩まされてきました。に変更してみましたSystem.getProperty("sss")か?

また、渡されたクロージャーには、プロパティを持つ@IfIgnoreデリゲートが設定されているため、代わりに試すことができます。それでも問題が解決しない場合は、コードを次のように変更して、クロージャーで使用可能なプロパティをデバッグできます。org.spockframework.runtime.extension.builtin.PreconditionContextsyssys["sss"]

@IgnoreIf({ println sys; sys["sss"].contains("true") })
于 2015-10-05T07:35:20.810 に答える