We can use the code directly to create a role and attach it to a user with system admin profile.
@isTest static void UserCreate() {
UserRole obj=new UserRole(Name= 'ABC');
insert obj;
Profile pf= [Select Id from profile where Name='System Administrator'];
String orgId=UserInfo.getOrganizationId();
String dateString=String.valueof(Datetime.now()).replace(' ','').replace(':','').replace('-','')
Integer RandomId=Integer.valueOf(Math.rint(Math.random()*1000000));
String uniqueName=orgId+dateString+RandomId;
User uu=new User(firstname = 'Alan',
lastName = 'McCarthy',
email = uniqueName + '@test' + orgId + '.org',
Username = uniqueName + '@test' + orgId + '.org',
EmailEncodingKey = 'ISO-8859-1',
Alias = uniqueName.substring(18, 23),
TimeZoneSidKey = 'America/Los_Angeles',
LocaleSidKey = 'en_US',
LanguageLocaleKey = 'en_US',
ProfileId = pf.Id,
UserRoleId = obj.Id);
}