You need to sign in to do that
Don't have an account?
SKriLL
Why does this test class succeed?
Hi guys and gals,
Why does this test succeed? I would expect it to fail...
@isTest(SeeAllData=false)
public class RepoBatchTest2
{
static testMethod void testMethod1()
{
List<Account> a1list = [select id from account where name = 'asdf1234asdf1234asdf1234asdf1234asdf1234asdf1234'];
integer i1 = 0;
for(account a : a1list)
{
i1++;
}
Account a = new Account();
a.name='asdf1234asdf1234asdf1234asdf1234asdf1234asdf1234';
insert a;
List<Account> a2list = [select id from account where name = 'asdf1234asdf1234asdf1234asdf1234asdf1234asdf1234'];
integer i2 = 0;
for(account a1 : a1list)
{
i2++;
}
System.assertEquals(i1,i2); //i1 should = 0 and i2 should = 1... both = 0??
}
}
Why does this test succeed? I would expect it to fail...
@isTest(SeeAllData=false)
public class RepoBatchTest2
{
static testMethod void testMethod1()
{
List<Account> a1list = [select id from account where name = 'asdf1234asdf1234asdf1234asdf1234asdf1234asdf1234'];
integer i1 = 0;
for(account a : a1list)
{
i1++;
}
Account a = new Account();
a.name='asdf1234asdf1234asdf1234asdf1234asdf1234asdf1234';
insert a;
List<Account> a2list = [select id from account where name = 'asdf1234asdf1234asdf1234asdf1234asdf1234asdf1234'];
integer i2 = 0;
for(account a1 : a1list)
{
i2++;
}
System.assertEquals(i1,i2); //i1 should = 0 and i2 should = 1... both = 0??
}
}
TLDR Version:
You have a typo. Change this:
To:
All Answers
According to code it will run fine.
first SOSL will try to fetch the data from account but it will not found and return a new instance of List of account so a1list has 0 size.
so i1 will be 0
Now you have inserted the account.
In second query soql it will fetch a single record and store in a2list.
now you have initlize i2=0;
And you try for loop on a1list but it has no any record so i2 will be zero.
and in last system assert will check that i1 and i2 both have zero value,
If you change the second for loop by a2list then it will give you error.
TLDR Version:
You have a typo. Change this:
To: