automated tests - Spock's @IgnoreIf Closure doesn't see System prop variable, set in jUnit's Suite -
i use geb + spock + junit runner + maven specs like:
@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: ... } }
i need run specs junit runner because need group in testsuites. found way set system property before testsuite run. available in junit 4.9 - @classrule. so, use here. way testsuites like:
@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') } } }
but @ignoreif behaviur doesn't work: doesn't see added system property 'sss' however, in feature method property available: when feature runs, gives next output:
running testsuite --> feature 1 runs --> mysystemprop is: true --> feature 2 runs
all run maven install. piece of 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>
what doing wrong? if correct - how can make work spock's @ignoreif , props, need define in junit testsuite? ( please, not offer use junit's @categories. )
thanks.
are sure properties['sss']
resolves right method call within closure passed @ignoreif
? have been bitten trying groovy in past, trying use kind of concise expressions static imports when resolving system props in particular. have tried changing system.getproperty("sss")
?
also, closure passed @ifignore
has delegate set org.spockframework.runtime.extension.builtin.preconditioncontext
has sys
property, try sys["sss"]
instead. if doesn't can debug properties available in closure changing code to:
@ignoreif({ println sys; sys["sss"].contains("true") })
Comments
Post a Comment