You need to sign in to do that
Don't have an account?
User reference in test class is returning all users instead of just the test user
Here is the test class:
@isTest public static void testBatch() { Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; User u2 = new User(Alias = 'standt', Email='standarduser@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com'); insert u2; Account a = new Account(Name = 'Test Account', ShippingPostalCode = '00000', BillingCountry = 'US', OwnerID= u2.Id, Inflows__c = 100, Outflows__c= 100, navmfv2__AUM_as_of__c = Date.today()); insert a; Test.StartTest(); FlowstoUser BatchClass = new FlowstoUser(); Database.executeBatch(BatchClass, 1); Test.StopTest(); }
Here's the error from test execution logs:
13:43:38.595 (2595524000)|CODE_UNIT_STARTED|[EXTERNAL]|01pZ00000005mN5|FlowstoUser
13:43:38.604 (2604439000)|SOQL_EXECUTE_BEGIN|[13]|Aggregations:0|Select Id, Inflow_of_Owned_Accounts__c, Outflow_of_Owned_Accounts__c from User
13:43:38.641 (2641706000)|SOQL_EXECUTE_END|[13]|Rows:18
13:43:38.643 (2643968000)|EXCEPTION_THROWN|[EXTERNAL]|System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.
As you can see, it's returning all of the users in the system PLUS the test user instead of just the test user. Any help would be greatly appreciated.
User data isn't isolated from tests, so you will get all users back from your query, see:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_data_access.htm
Can you post the code that is actually causing the error to be thrown.
Sure.
How can I create a successful test class if I can't isolate my test user? The idea is it would be a batchable class to sum up the inflow and outflow fields on the accounts they own.
I got around it by setting up an If statement in my query formation that checks to see if test data exists. Like so: