+ Start a Discussion
Dhilip DussaDhilip Dussa 

Need Help Lightining test class

I need Help on Test class with assert how to add assert in this test class

public class TestClass{
    public static Account returnAccount(Id ParentId) {
        return [Select Name, FirstName, LastName, Id from Account where id =: ParentId];
    public static void test(){
    Account a = new Account();
    insert a;
    //need add assert here if I comment above line assert has to fail o/w it hass to pass

Alain CabonAlain Cabon

Account a = TestClass.returnAccount(a.id);
System.assertEquals('Test', a.Name,'Account Name different');

System.assertEquals(expected, actual, msg)
Asserts that the first two arguments are the same. If they are not, a fatal error is returned that causes code execution to halt.
msg Type: Object (Optional) Custom message returned as part of the error message.
Deepali KulshresthaDeepali Kulshrestha
Hi Dhilip,

I have gone through your problem, Please try below code:

public class TestClass_Test {
    @isTest private static void test()
        Account a = new Account();
        insert a;
        Account acc= [select Id,Name from Account];
        system.assertEquals('Test', acc.Name);

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha