O'Reilly logo

Testing with F# by Mikael Lundin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Don't mock the Mockingbird

Let us take a look at the following code:

// don't [<Test>] let ``should first get customers from customer service and then store them to hard drive`` () = // arrange let customerService = MockRepository.GenerateMock<ICustomerService>() let fileSystem = MockRepository.GenerateMock<IFileSystem>() let cacheJob = CacheJob(customerService, fileSystem) // setup mocks customerService.Expect(fun service -> service.GetCustomers()).Return([(1, "Mikael Lundin")]) |> ignore fileSystem.Expect(fun fs -> fs.AppendLineToFile("customer.txt", "1,Mikael Lundin")) |> ignore // act cacheJob.Execute() |> ignore // assert customerService.VerifyAllExpectations() fileSystem.VerifyAllExpectations() // do // simplify the SUT or implement a vertical ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required