Your test is weird. You select existing accounts. There are none. You have a piece of batch copy-pasted - why? Even if it'd work - how would you distinguish between what the test did and what the batch did?
You'd have to insert some accounts first. I think the error you get is from test's line 21 but the problems (including "Execute method is not covering in the code") are earlier.
Next time include the test's code too, screenshots are painful to retype.
I think you need something like this (there might be typos!)
private static void testBatch(){
List<Account> accs = new List<Account>{
new Account(Name = 'Unimportant'),
new Account(Name = 'Whatever', Description = 'blah blah...')
};
insert accs;
Test.startTest();
Database.executeBatch(new BatchApexOnAccount());
Test.stopTest();
for(Account a : [SELECT Name, Description FROM Account]){
System.assertEquals('Salesforce', a.Name);
System.assert(a.Description.startsWith('Update account'));
}
}
Edit: another user suggested following edit to my post. I don't agree with it but I'll put it here to preserve the idea and he can always post his own answer with improvements/reasoning.
https://stackoverflow.com/users/6718505/waldemar-liedle
All Assets (sic) in a Loop is a Bad Idea. When no Accounts are Inserted, the Test would still succeed. I would also Check something Outside Loop
List<Account> testAccs = [SELECT Name, Description FROM Account];
System.assertEquals(accs.size(), testAccs.size());
for(Account a : testAccs){
System.assertEquals('Salesforce', a.Name);
System.assert(a.Description.startsWith('Update account'));
}
So...
- I don't think it matters because accounts are inserted earlier in the test. You'd need to completely mess the batch job up so it'd start deleting accounts for this query to fail finding any.
- normally tests see only data that was inserted during test so it's not like it'll query thousands here (you'd run into other problems like "in test there can be only 1 execute()" so 200 accounts max)
- in extreme cases querying all records to a List instead of looping through query (silently calling queryMore() when needed) will eat lots of memory