function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shruthi MN 19Shruthi MN 19 

Bacth test class error

@istest
private class Accountupdate {
    @istest
    static void tetslead(){
        List<Account> l= new List<Account>();
        Account a= new Account();
        a.Name='surya';
        a.Phone='123';
        l.add(a);
        insert l;
   
    Test.startTest();
    Accountupdate ap= new Accountupdate();
    Id jobid= Database.executeBatch(ap);
    Test.stopTest();
    }
}

class

global class Accountupdate implements Database.Batchable<sObject>
{

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT Id,Name,Phone FROM Account ';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        for ( Account a : scope)
        {
           a.Phone='123';
        }
        update scope;
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

I am getting below error

User-added image
SarvaniSarvani
Hi Shruthi,

Change your test class (Class Name) from AccountUpdate to Something else like AccountUpdateTest (Like below). It gives you error as it finds conflict between Actual batch class name and test class name as the same. 
 
@istest
private class AccountupdateTestClass { // Changed your Class name
    @istest
    static void tetslead(){
        List<Account> l= new List<Account>();
        Account a= new Account();
        a.Name='surya';
        a.Phone='123';
        l.add(a);
        insert l;
   
    Test.startTest();
    Accountupdate ap= new Accountupdate();
    Id jobid= Database.executeBatch(ap);
    Test.stopTest();
    }
}

Hope this helps! Please mark as best answer if it does

Thanks,
Sarvani