Skip to main content

unit tests

Deal with time dependencies in Tests
·493 words·3 mins
dotnet unit tests xunit
Las week we discovered that some of our test would"randomly" fail depending of the time of the day. After investigating the issue we found that the culprit was that the service being tested was taking decisions based on the current system time (DateTime.Now) leading to different outcomes through the day. So how do we deal with time dependencies in tests?
Rhino Mocks Method ‘YYY' requires a return value or an exception to throw.
·164 words·1 min
dotnet unit tests
Yesterday I found myself stucked with a strange exception while programming a unit test using Rhino Mocks. Supose you have an interface like the following one. public interface ITest { object Freak(); } You can try a mock like the following: var test = MockRepository.GenerateMock(); test.Expect(t => t.Freak()).IgnoreArguments() .WhenCalled(x => x.ReturnValue = "THIS IS A RETURN VALUE") .Repeat.Any(); Calling test.Freak(); will result in a return value of “THIS IS A RETURN VALUE"