Tips to writing good Unit Tests
https://developer.salesforce.com/blogs/developer-relations/2016/07/six-tips-great-unit-tests.html
@isTest static void User_can_get_contact_email()
{
// Arrange
System.runAs(createUser())
{
// Act
// Assert
system.assertEquals('contact@place.com', contact.Email, 'Email does not match');
}
}
public static User createUser()
{
Profile profile = [select Id from profile where name = 'Standard User'];
User user = new User(
Alias = 'standard',
Email = 'standarduser@testorg.com',
EmailEncodingKey = 'UTF-8',
LastName = 'Testing',
LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_GB',
ProfileId = profile.Id,
TimeZoneSidKey = 'Europe/London',
UserName = 'standardusertesting@gearsettest.com'
);
return user;
}