私は 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 の使用を提案しないでください。)
ありがとう。