A method in my class I'm testing is suppose to return all users in the org, plus an extra user empty user at the beginning of the list. The reason for this is I wanted the default to be empty.
@AuraEnabled
public static List<User> getUsersDB() {
// Create empty user
User u = new User();
// Create empty list for users
List<User> users = new List<User>();
//Add empty user to list
users.add(u);
//Get all users in org and add to list
List<User> addedUsers = [SELECT Id, Name FROM User];
users.addAll(addedUsers);
return users;
}
This is the results on the front end
Now I'm trying to test this method in my test class.
@isTest
class WhiteboardItemsApexControllerTest {
static testMethod void whiteboardItemDBTest() {
User u = new User();
u.UserName = 'FirstName.LastName@company.com';
u.Email = 'FirstName.LastName@company.com';
u.FirstName = 'FirstName';
u.LastName = 'LastName';
u.Alias = 'flast';
u.ProfileId = '00ed0000000uSiX';
u.TimeZoneSidKey = 'GMT';
u.LocaleSidKey = 'en_US';
u.EmailEncodingKey = 'ISO-8859-1';
u.LanguageLocaleKey = 'en_US';
u.UserPermissionsMobileUser = false;
insert u;
User u2 = new User();
List<User> users = new List<User> {u2, u};
System.assertEquals(users, WhiteboardITemsApexController.getUsersDB());
}
}
For some strange reason, it's returning all the users in my org, in addition to the test users I created.
System.AssertException: Assertion Failed: Expected: (User:{}, User:{Username=FirstName.LastName@company.com, Email=FirstName.LastName@company.com, FirstName=FirstName, LastName=LastName, Alias=flast, ProfileId=00ed0000000uSiXAAU, TimeZoneSidKey=GMT, LocaleSidKey=en_US, EmailEncodingKey=ISO-8859-1, LanguageLocaleKey=en_US, UserPermissionsMobileUser=false, Id=005d0000006FY7QAAW}),
Actual: (User:{}, User:{Id=005d0000002kt1DAAQ, Name=Leigh Blair}, User:{Id=005d0000000xloEAAQ, Name=Zack Woodmansee}, User:{Id=005d0000006FY7QAAW, Name=FirstName LastName}, User:{Id=005d0000005NR4WAAW, Name=Tyler Zika}, User:{Id=005d0000000xlRkAAI, Name=Chatter Expert})
Why is that?
Best Answer