Your org has a validation rule that requires a value for a Manager field (ManagerID) on User. Ideally you would create a second test User to assign as your first test User's manager. You get into a chicken and egg scenario though, because you can't create and insert a test Manager without providing their manager.
Solution 1:
Create two test Users, assign them as each other's managers, and insert them at the same time (lol):
Profile pro = [SELECT Id FROM Profile WHERE Name='Standard User'];
User testUserA = new User(
Alias = 'standard', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = pro.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
User testUserB = new User(
Alias = 'standard', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = pro.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
testUserA.ManagerID = testUserB.id;
testUserB.ManagerID = testUserA.id;
List<User> usersToInsert = new List<User>();
usersToInsert.add(testUserA);
usersToInsert.add(testUserB);
insert usersToInsert;
// rest of test here
Solution 2:
Use @isTest(seeAllData=true)
and query for an actual User ID to use as a dummy Manager for your test Users:
User dummyManager = [SELECT Id, Name FROM User WHERE Name = 'RAHUL SRIVASTAVA' LIMIT 1];
User u = new User(
ManagerID = dummyManager.id, // provide a value for Manager here
Alias = 'standtrd', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing',
LanguageLocaleKey='en_US', LocaleSidKey='en_US',
ProfileId = pro.Id, TimeZoneSidKey='America/Los_Angeles',
UserName='[email protected]');
insert u;
// rest of test here
While there is an open proposal for a system option to disable validation rules during test scenarios, it would kind of eliminate the point of testing in the first place, so I wouldn't hold my breath and wait on it for a solution :P
There is almost certainly a better solution than this, I will be interested to hear what more experienced folks recommend in this situation :)