+ Start a Discussion
prasanth kumarprasanth kumar 

test class on account is not working . pleas help

i wote a apex class and test class.  no errors are showing. when i click on run test. then it is not working. please help
 
test class

@istest
public class testinsertaccount {

    testmethod static void mytest()
    {
        account acc=new account(name='jaddd');
        insert acc;
        integer a=[select count() from account];
    insertaccount i1=new insertaccount();
        i1.insert1();
        integer b=[select count() from account];
        system.assertequals(a,b);
    
    }
    
}





apex class:-

public class insertaccount {
    public account acc;
    public void insert1()
    {
        acc=new account(name='yugandhar',industry='banking');
        insert acc;
    }
    
    }

 
Best Answer chosen by prasanth kumar
Shrikant BagalShrikant Bagal
Please use following testClass :
 
@istest
public class testinsertaccount {

    testmethod static void mytest()
    {        
       insertaccount classInstance =new insertaccount();
        classInstance.insert1();
        Account account =[select Id,Name from account Where name = 'yugandhar' LIMIT 1 ];
        system.assert(account != null);    
    }
    
}

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 

All Answers

Shrikant BagalShrikant Bagal
Please use following testClass :
 
@istest
public class testinsertaccount {

    testmethod static void mytest()
    {        
       insertaccount classInstance =new insertaccount();
        classInstance.insert1();
        Account account =[select Id,Name from account Where name = 'yugandhar' LIMIT 1 ];
        system.assert(account != null);    
    }
    
}

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Please try below test class:-
@istest
public class testinsertaccount 
{
    testmethod static void mytest()
    {
		insertaccount obj = new insertaccount();
		obj.insert1();
    }
}

Please read more about for test classes in below blog.
http://amitsalesforce.blogspot.in/2015/06/best-practice-for-test-classes-sample.html

Please mark this as solution if this will help you
Ajay K DubediAjay K Dubedi
Hi Prasant,
try this test class
@isTest
public class testinsertaccount {
 
    static testmethod void mytest()

    {       
      Account accobj=new Account();
      accobj.Name='yugandhar';
      accobj.Industry='banking';
      insert accobj;
    
      insertaccount control = new insertaccount();
      control.insert1();
    } 
}

 
Shrikant BagalShrikant Bagal
If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks!