When running tests on multiple machines and CI systems distributed around the globe, the system's time zone can cause inconsistencies in test results.
ApprovalTests provides a convenience class, WithTimeZone
, to set a consistent time zone for a block of code. This ensures that all code within the block uses the same time zone, avoiding inconsistencies caused by different system time zones.
Here is an example:
try (WithTimeZone tz = new WithTimeZone("UTC"))
{
// All code within this block will see the computer as being in the UTC time zone
}
// The computer's time zone will revert to previous setting here