You need to sign in to do that
Don't have an account?
Giri Kumar B
i am writing class account and contact insert record. same class i write the test class but not code coverage 100% . were i am miss the logic
class
---------------
public class textex2 {
public string lastname ;
public string phone;
public void create(){
if(phone == '123'){
account acc = new account();
acc.name = lastname;
acc.Phone = phone;
insert acc;
}else{
contact c = new contact();
c.lastname = 'test1';
c.phone = '0223';
insert c;
}
}
}
------------------------
test
@istest
public class testclassex2 {
@istest
static void testdata2(){
textex2 ts = new textex2();
ts.lastname = 'test1';
ts.phone = '125';
ts.create();
if(ts.phone == '123'){
integer count = [select count() from account];
system.assertEquals(count, 1);
}
ts.phone ='0234';
ts.create();
if(ts.phone != '123'){
integer size = [select count() from contact];
system.assertEquals(size,1);
}
}
}
---------------
public class textex2 {
public string lastname ;
public string phone;
public void create(){
if(phone == '123'){
account acc = new account();
acc.name = lastname;
acc.Phone = phone;
insert acc;
}else{
contact c = new contact();
c.lastname = 'test1';
c.phone = '0223';
insert c;
}
}
}
------------------------
test
@istest
public class testclassex2 {
@istest
static void testdata2(){
textex2 ts = new textex2();
ts.lastname = 'test1';
ts.phone = '125';
ts.create();
if(ts.phone == '123'){
integer count = [select count() from account];
system.assertEquals(count, 1);
}
ts.phone ='0234';
ts.create();
if(ts.phone != '123'){
integer size = [select count() from contact];
system.assertEquals(size,1);
}
}
}
All Answers
Let us know if this will help you