[SalesForce] How to use Ids of the test data factory records in test class

Created a DataFactory class to reuse the code in test classes. I am not able to get the List of users record id into the test class. Can anyone please help me with this?

It is currently throwing Error : Initial term of field expression must be a concrete SObject: List

TestDataFactory Apex class:

@isTest
public class testDataFactory{
    public Static List<User> cuser(){

        List<User> UsersList = new List<User>();

        Profile p = [SELECT Id FROM Profile WHERE Name='Profile1'];
        User usr1 = new User(Alias = 'aa', Email='testuser111@testorg.com',
        EmailEncodingKey='UTF-8', FirstName='yhsl',LastName='test', LanguageLocaleKey='en_US',
        LocaleSidKey='en_US', ProfileId = p.Id,
        TimeZoneSidKey='America/Los_Angeles', UserName='testuser111@testorg.com');
        UsersList.add(usr1);
        User usr2 = new User(Alias = 'ab', Email='testuser1112@testorg.com',
        EmailEncodingKey='UTF-8', FirstName='iuqwet',LastName='Test', LanguageLocaleKey='en_US',
        LocaleSidKey='en_US', ProfileId = p.Id,
        TimeZoneSidKey='America/Los_Angeles', UserName='testuser1112@testorg.com');
        UsersList.add(usr2);
        insert UsersList;
        return UsersList;
    }

}

Test Class:

@isTest
private class TestClass
{
    Account Acc = new Account(Name='Test');
    Insert Acc;
    Acc.ownerId = testDataFactory.cuser().UsersList[0].id; // It is throwing Error : Initial term of field expression must be a concrete SObject: List<User>
    update Acc; 
} 

Best Answer

The class TestClass does not have access to the UsersList variable in the current configuration, since UsersList only has scope in the cuser() method (that is, it doesn't exist outside of the method). Rather than trying to access UserList directly, try accessing the reference to the list that is returned by the method. Change

Acc.ownerId = testDataFactory.cuser().UsersList[0].id;

to

Acc.ownerId = testDataFactory.cuser()[0].id;