F#ã®UnitTest Framework FsUnit
FsUnit
http://fsunit.codeplex.com/
NUnitã®æ©è½ã使ãããªã®ã§NUnitãå¥éã¤ã³ã¹ãã¼ã«ãã¾ãã*1
FsUnitæ¬ä½ã®ã³ã¼ãã¯ãã£ãã®ããã ãã
http://fsunit.codeplex.com/sourcecontrol/network/Show?projectName=fsunit&changeSetId=7611206edf25#SourceCode%2fFsUnit.NUnit%2fFsUnit.fs
使ãæ¹ã¯ä¸è¨ã®FsUnitã®ããããã¼ã¸ã«è¼ã£ã¦ããã®ã§ããããã¹ãã³ã¼ãã®ã¯ã©ã¹åãã¡ã½ããåããã¡ã³ãã¼ã§ãã
æç« â¦ï¼ã»ã»ï¼
type LightBulb(state) = member x.On = state override x.ToString() = match x.On with | true -> "On" | false -> "Off" [<TestFixture>] type ``Given a LightBulb that has had its state set to true`` ()= let lightBulb = new LightBulb(true) [<Test>] member test. ``when I ask whether it is On it answers true.`` ()= lightBulb.On |> should be True [<Test>] member test. ``when I convert it to a string it becomes "On".`` ()= string lightBulb |> should equal "On"
èªä½ã®ããã°ã©ã ã対象ã«ç°¡åãªãã¹ãã³ã¼ããæ¸ãã¦ã¿ã¾ãã
ãã¹ã対象ã®ã¯ã©ã¹ã®ã³ã¼ãã¯ããã
http://github.com/hayashih/EpubCreator/blob/master/EpubCreator.fs
ãã¹ãã³ã¼ã
[<TestFixture>] type ``EpubCreator Test`` ()= let epub = new Name.hayashih.Epub.EpubCreator() //do epub.Author <- "hayashih" // æåããå ´å do epub.Author <- "nanashi no gonbei" // 失æããå ´å [<Test>] member x. ``Check author.`` ()= epub.Author |> should equal "hayashih" let Main() = try let test = ``EpubCreator Test`` () test.``Check author.`` () with | :? NUnit.Framework.AssertionException as ex -> printfn "%s" ex.Message; [<STAThread>] do Main()
æåã®å ´åã¯ä½ãèµ·ããã¾ãããã失æããå ´åã¯ä¾å¤ã§NUnit.Framework.AssertionExceptionããã¾ããä¸è¨ã®ããã«æã¾ãã¦ã¨ã©ã¼ã¡ãã»ã¼ã¸ã表示ããã¨
Expected string length 8 but was 17. Strings differ at index 0. Expected: "hayashih" But was: "nanashi no gonbei" -----------^
ã¨ãã表示ãã§ãã¾ãã
*1:MbUnit http://www.mbunit.com/ ã¨ãããã¹ããã¬ã¼ã ã¯ã¼ã¯ã¨çµã¿åããããã¨ãã§ãããããã