F#ã§NUnitãã¹ãã³ã¼ããè¨è¿°ããæ¹æ³1
F#ã§NUnitãã¹ãã³ã¼ããè¨è¿°ããæ¹æ³
F#ã¨NUnitã§åä½ãã¹ããè¨è¿°ããæ¹æ³ãææ¢ãã§èª¿ã¹ã¾ããã
åæ
- Visual Studio 2010 Professional
- NUnit 2.5.7
ãå©ç¨ãã¦ããã¾ãããã®ä»ã®ç°å¢ã§ã¯ç¢ºèªãã¦ããã¾ããã®ã§ãäºæ¿ä¸ããã
ãã¹ã対象ããã°ã©ã
ãã¹ããããããã°ã©ã (F#ã©ã¤ãã©ãª)ãTestedProgramã¨ãã¾ãã
[ãã¡ã¤ã«]->[æ°è¦ä½æ]->[ããã¸ã§ã¯ã]->[ä»ã®è¨èª]->[Visual F#]->[F# ã©ã¤ãã©ãª]
ãé¸æããååã[TestedProgram]ã¨ãã¦ä¸ããã
被ãã¹ãã³ã¼ãã®è¨è¿°
Module1.fsãéããããã©ã«ãã§å ¥åããã¦ããã
module Module1
ãåé¤ãã¦ä¸è¨ãå ¥åãã¦ä¸ããã
namespace TestedNamespace module TestedModule= let square x = x * x let squareF (x : int) = (float x) * (float x) let rec qsort = function | [] -> [] | pivot :: rest -> let is_less x = x < pivot in let left, right = List.partition is_less rest in qsort left @ [pivot] @ qsort right
- int -> int ã® squareã¡ã½ãã
- int -> float ã® squareFã¡ã½ãã
- a' list -> a' list ã® qsortã¡ã½ãã
ä¸è¨3ã¤ã®ã¡ã½ããã«å¯¾ãã¦ãNUnitãã¹ãã³ã¼ããæ¸ãã¦è¡ãã¾ãã
é·ããªãã®ã§ããã®ã¨ã³ããªã§ã¯æºåã®ã¿è¨è¿°ãã¾ãã
ä»åã¯ãã¹ãã³ã¼ãã®æ¸ãæ¹ãæ¤è¨¼ããã®ã§ããã®æç¹ã§ä¸è¨ããã°ã©ã ããã«ãããF# Interactiveã«ããã¦æ£å¸¸ã«åä½ãããã¨ã確èªãã¦ããã¦ãã ããã
F# Interactiveã¯[表示]->[ãã®ä»ã®ã¦ã£ã³ãã¦]->[F# Interactive]
ãé¸æãããã¨ã§èµ·åã§ãã¾ãã
ãã¹ãããã°ã©ã
ãã¹ãããããã°ã©ã (F#ã©ã¤ãã©ãª)ãTestingProgramã¨ãã¾ãã
[ãã¡ã¤ã«]->[追å ]->[æ°ããããã¸ã§ã¯ã]->[ä»ã®è¨èª]->[Visual F#]->[F# ã©ã¤ãã©ãª]
ãé¸æããååã[TestingProgram]ã¨ãã¦ä¸ããã
ãã¹ã対象ããã°ã©ã ã®é¸æ
ã½ãªã¥ã¼ã·ã§ã³ã¨ã¯ã¹ããã¼ã©ã¼å
ã®TestingProgramã®[åç
§è¨å®]ãå³ã¯ãªãã¯ãã
[åç
§ã®è¿½å ]ãããã¹ã対象ããã°ã©ã ãé¸æãã¾ãã
ä»åã¯å½ç¶ã[Projects]->[TestedProgram]ã§ããã
NUnitFrameworkã¸ã®åç §ã®è¿½å
TestingProgramã®[åç §è¨å®]ãå³ã¯ãªãã¯ãã[åç §ã®è¿½å ]->[Assemblies]->[Extensions]->[nunit.framework]ã追å ãã¾ãã
ãã¹ãã³ã¼ãã®è¨è¿°
TestingProgramå ã®Module1.fsãéããããã©ã«ãã§å ¥åããã¦ããã
module Module1
ãåé¤ãã¦ä¸è¨ãå ¥åãã¦ä¸ããã
module TestingNamespace.TestingModule open System open NUnit.Framework open TestedNamespace.TestedModule [<TestFixture>] type MyTest() = [<Test;Description("example description")>] member x.TestSquare1 () = Assert.AreEqual (4, square 2)
ãã®æç¹ã§ãsquareã¡ã½ããã«å¯¾ãããã¹ããä¸ã¤æ¸ãã¾ããã
ãã¹ããã
[ãã«ã]->[ã½ãªã¥ã¼ã·ã§ã³ã®ãã«ã]ã§ãã«ããè¡ãã¾ãã
ããã§ãã¨ã©ã¼ãåºããªããã¿ã¤ããã¹ãªã©ã®å¯è½æ§ãããã¾ãã
é·ããªã£ãã®ã§ãç¶ãã¯æ¬¡ã®ã¨ã³ããªã«ã¦ã