@isTest
public class QWE_Integration_BatchTest {
public static testMethod void metodoTest(){
QWE_Integration__c rec = new QWE_Integration__c();
rec.First_Name__c = 'Kinder';
rec.Last_Name__c = 'Lak';
rec.Email__c = '[email protected]';
}
insert rec;
Database.executeBatch(new QWE_Integration_Batch());
List<Account> listAcc = [SELECT ID, Name from Account];
// system.assert( .....)
}
1 Answer
First of all, you must wrap your batch invocation in Test.startTest()
and Test.stopTest()
, or your asynchronous code will not run inside the context of your unit test. See How do I test asynchronous Apex? for more details.
Then, you must write assertions about what you believe to be true of the data in listAcc
after your code has run. The reference for the System
class explains all of the available assertion calls. In most cases, you'll want to use the form
System.assertEquals(expectedValue, actualValue, message)
where expectedValue
is what you think you should have, actualValue
is the actual result, and message
is a message to show if the assertion fails to clarify what is wrong.
Here, you might write two assertions that look something like this:
System.assertEquals(1, listAcc.size(), 'expected one Account');
System.assertEquals('Kinder', listAcc[0].Name, 'expected Account named Kinder');
We link numerous resources on how to write high-quality test code at How do I write an Apex unit test?.