ãã·ã¸ã§ã³ãã¼ãã«ã¨Spockã§è©¦ãTDDï¼ãã¿ï¼
â»ãã®è¨äºã¯ã¡ã¢æ¸ãã§ã
â»ãã®è¨äºã«ã¯çªã£è¾¼ã¿ã©ããæºè¼ã®ã³ã¼ããå«ã¾ãã¦ãã¾ããã¤ã¾ããããããã¨ã§ãã
- (1/22ä¿®æ£)ã³ã¼ããä¸é¨ä¿®æ£
ãã·ã¸ã§ã³ãã¼ãã«ã¨Spockã使ã£ã¦TDDããã¨ã©ããªããã¨ãããã¨ããFizzBuzzã§è©¦ãã¦ã¿ã¾ãããã
ç¨æãããã®
- CEGTestããèªåçæããããã·ã¸ã§ã³ãã¼ãã«
- ãã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯Spock
- Groovyãªç°å¢
ãã·ã¸ã§ã³ãã¼ãã«ãã¤ãã
CEGTestã使ã£ã¦åå çµæã°ã©ããæ¸ãã¾ããããããã¨ãã·ã¸ã§ã³ãã¼ãã«ã¯åæã«èªåçæããã¦ããã¯ãã§ãã
ãã·ã¸ã§ã³ãã¼ãã«ããã®ã¾ã¾Spockã«ç§»æ¤ãã¦ã¿ã
ãã·ã¸ã§ã³ãã¼ãã«ããã®ã¾ã¾ä½¿ãããªããGroovyããããªãã¨ãSpockãããªãã¨ããè¨ã訳ã¯ã§ãã¾ããããï¼
import spock.lang.Specification import spock.lang.Ignore class FizzBuzzTest extends Specification { @Ignore def "ä¸ããããæ°å¤ã«ãã£ã¦æå®ã®FizzBuzzæååãè¿ã" () { where: ä¸ã®åæ° << [ true , false , true , false ] äºã®åæ° << [ false , true , true , false ] Fizzãè¿ã << [ true , false , false , false ] Buzzãè¿ã << [ false , true , false , false ] FizzBuzzãè¿ã << [ false , false , true , false ] å¤ãæååã§è¿ã << [ false , false , false , true ] } }
whereã¯Parameterized Testãè¨è¿°ããããã«ä½¿ãã®ã§ããâ¦ãããããæ¸ãã¦ã¿ãã¨ãã·ã¸ã§ã³ãã¼ãã«ãã®ã¾ã¾ã§ããã
ã§ãTDDããã¨ãã«ã¯éªéã ãªã¼ã¨æããªãããªãã®ã§
ãã£ã¤TDD
ãã¨ã§ãã
Ignoreãã¯ããã¦ãã¹ããåãããã«ãã
ãã·ã¸ã§ã³ãã¼ãã«ãå©ç¨ãããã¹ãã³ã¼ããå®è¡ã§ããããã«æç´ããã¾ãã
ã¡ãªã¿ã«ãä»åã¯TDDæã«æ¸ãããã¹ãã³ã¼ãã¯æ¨ã¦ããã¨ã«ãã¾ããã
import spock.lang.Specification class FizzBuzzTest extends Specification { def "ä¸ããããæ°å¤ã«ãã£ã¦æå®ã®FizzBuzzæååãè¿ã" () { setup: def otherNum = 2 def num = {if(ä¸ã®åæ° && äºã®åæ°) 15 else if(ä¸ã®åæ°) 3 else if(äºã®åæ°) 5 else otherNum}.call() def result = {if (Fizzãè¿ã) 'Fizz' else if(Buzzãè¿ã) 'Buzz' else if(FizzBuzzãè¿ã) 'FizzBuzz' else otherNum.toString()}.call() expect: sayFizzBuzz(num) == result // ãã®æ¸ãæ¹ãOKãããæ¸ããæ¹ãè¦ãããããï¼ where: ä¸ã®åæ° | äºã®åæ° | Fizzãè¿ã | Buzzãè¿ã | FizzBuzzãè¿ã | å¤ãæååã§è¿ã true | false | true | false | false | false false | true | false | true | false | false true | true | false | false | true | false false | false | false | false | false | true } def sayFizzBuzz(def num) { if(num % 15 == 0) 'FizzBuzz' else if(num % 3 == 0) 'Fizz' else if(num % 5 == 0) 'Buzz' else num.toString() } }
ãã¹ãå®è¡â¦ã¯ããéãã¾ããã
ãªã«ãããããã®ï¼
CEGTestã§åå çµæã°ã©ããæ¸ãã°ãã·ã¸ã§ã³ãã¼ãã«ããããã¦(ã¸ã§ãã¬ã¼ããã¼ã«èªä½ããã°)ãã·ã¸ã§ã³ãã¼ãã«ããSpockã³ã¼ããä¸é¨èªåçæã§ããã¨ããããã³ãæãç«ã¡ã¾ãã
以ä¸ã誰å¾è¨äºã§ããã