ä»»æã®ãã£ã¼ãã£ã¼ã¡ã½ããã ããå®è¡ãã
Spock ã§ã JUnit4 ã®Category ã¨åãããã« ä»»æã®ãã¹ã (ãã£ã¼ãã£ã¼) ã ããå®è¡ãããã¨ãéã«ã¹ããããããã¨ãã§ãã¾ãã
æ¹æ³ã¯ç°¡åã§ãã
ããããããSpecification (ãã¹ãã¯ã©ã¹) ããã㯠ãã£ã¼ãã£ã¼ (ãã¹ãã¡ã½ãã) ã«
好ããªã ãã¢ããã¼ã·ã§ã³ãã¤ãã¾ãããã
ãã¨ã¯ è¨å®ãã¡ã¤ã«ã« å®è¡ããã (ãããã¯ã¹ãããããã) ã¢ããã¼ã·ã§ã³ã
æå®ããã ãã§ãã
ã§ã¯ãã¾ã㯠ã¢ããã¼ã·ã§ã³ãä½æãã¾ãããã
ä»å㯠Java ã§ä½æãã¾ãããããã¡ãã Groovy ã§ä½æãã¦ã OK ã§ãã
package com.bluepapa32; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) @interface Fast {}
package com.bluepapa32; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) @interface Slow {}
package com.bluepapa32; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) @interface Server {}
次㫠ä½æããã¢ããã¼ã·ã§ã³ã Specification (ãã¹ãã¯ã©ã¹) ããã㯠ãã£ã¼ãã£ã¼ (ãã¹ãã¡ã½ãã) ã«ä»ãã¾ãããã
@Server class HelloSpec extends Specification { @Fast def "a fast method"() { expect: true } @Slow def "a slow method"() { expect: true } def "a neither fast nor slow method"() { expect: true } }
å¾ã¯ å®è¡ãããã¢ããã¼ã·ã§ã³ã¨ã¹ããããããã¢ããã¼ã·ã§ã³ã 次ã®ããã«è¨å®ãã¡ã¤ã«ã«è¨å®ããã ãã§ãã
import com.bluepapa32.* runner { include Server // å®è¡ããããã® exclude Fast, Slow // ã¹ãããããããã® }ä¸è¨ã¯ @Server ãä»ãã ãã£ã¼ãã£ã¼ã®ãã¡ @Fast 㨠@Slow ãä»ãã¦ããªããã®ã ããå®è¡ããããã«è¨å®ãã¦ãã¾ãã
ä»åã®å ´åã 㨠"a neither fast nor slow method" ã ããå®è¡ããããã¨ã«ãªãã¾ãã
ä¸è¨ã®è¨å®ã¯
- ã·ã¹ãã ãããã㣠spock.configuration ã«è¨å®ãããã¡ã¤ã« (ä¾: -Dspock.configuration=MySpockConfig.groovy)
- ã¯ã©ã¹ãã¹ä¸ã® SpockConfig.groovy
- ${user.home}/.spock/SpockConfig.groovy
ãããEclipse ãå©ç¨ãã¦ããã®ã§ãã㰠以ä¸ã®ããã«è¨å®ãã¡ã¤ã«ãä½æãã¾ãããã
ã¾ããSpecification ã¯ã©ã¹ç¨ã®ã½ã¼ã¹ãã©ã«ãã¨ã¯å¥ã®ã½ã¼ã¹ãã©ã«ã (ä¾ãã° src/test/resources) ãä½æãã¾ãã
次ã«ããã®ç´ä¸ã« SpockConfig.groovy ãä¸è¨ã®å
容ã§ä½æãã¾ãã
æå¾ã« Groovy ã®è¨å®ã® ãCompilerã ã® ãEnable script foler supportã ã«ãã§ãã¯ãããã¾ãã
ãã㯠src/test/resources é
ä¸ã® groovy ãã¡ã¤ã«ã class ãã¡ã¤ã«ã«ã³ã³ãã¤ã«ãããªãããã«ããããã§ãã
ã¨è¨ãã®ã SpockConfig.groovy ãã¡ã¤ã«ã¯è¨å®ãã¡ã¤ã«ã§ãã®ã§ groovy ãã¡ã¤ã«ã®ã¾ã¾ã¯ã©ã¹ãã¹ä¸ã«ã³ãã¼ãããå¿
è¦ãããããã§ãã
ã¡ãªã¿ã« è¨å®ãã¡ã¤ã«ã«ã¯ ã¢ããã¼ã·ã§ã³ã®ä»ã«ãå®è¡ããã Specification ãç´æ¥æå®ãããã¨ãã§ãã¾ãã
ä¸è¨ã® HelloSpec ã® Slow 以å¤ã®ãã£ã¼ãã£ã¼ã¡ã½ããã ããå®è¡ãããå ´åã¯ä»¥ä¸ã®ããã«è¨å®ãã¾ãã
import com.bluepapa32.* runner { include HelloSpec exclude Slow }