/images/avatar.png

Tech Lead and AWS Developer

Fake static property DateTime.Now() with a DateTime Provider

๐Ÿ”Š Voiced by Amazon Polly Our code is often time-dependent. We use the date or time to implement logic and make decisions in our code. The behavior of DateTime.Now or DateTime.UtcNow can differ due to the system, timezone and the time change (summer/winter). This means that we have to control this for our tests. Take this method for instance: public double ReturnCurrentOffset() { var result = DateTime.Now - DateTime.UtcNow; return result.

Share context between tests with fixtures

๐Ÿ”Š Voiced by Amazon Polly Test Fixtures Imagine your about to sit down to eat your lunch. The dirty breakfast dish is still on the table. You got three options. You can get a new plate, you can clean the old plate, or you can just eat lunch off the dirty plate. Thats it. New plate, clean plate, dirty plate. The same rules apply to tests. Transient Fresh Fixture Getting a new plate is what Meszaros calls in the book “XUnit Test Patterns” a Transient Fresh Fixture.

Create Test Data cleanly with Fluent Builder Pattern

๐Ÿ”Š Voiced by Amazon Polly Helper methods make it easier to create test data. But they can become difficult to read over time as you need more variations of the test data to satisfy constantly evolving requirements from new tests. Let say, we have the following Customer class. public class Customer { public string Name { get; set; } public DateTime? DateOfBirth { get; set; } public string Email { get; set; } public string Address { get; set; } } In generally we create an instance of the Customer and set the respective properties as shown below.