You need to sign in to do that
Don't have an account?
Gorky
Class Testing. Not Covered Warnings.
Hello everyone,
First of all I want to say I'm new with Force for Eclipse.
When i'm trying to test this class, Eclipse returns 'line not covered' warning.
I tried it on develop and it works, then when I want to pass the test in order to deploy it to production, all turns in a strange mess...
Why those warnings? Even if only leave the class with a simple method it returns warnings... Anyone can tel me what I'm doing wrong.
Thanks :)
... the code:
public class Test_Class {
public static void checkOrderNumber(OpportunityLineItem[] accs){ --> Waits for a table results
for (OpportunityLineItem a:accs){ --> For items on the table received...
Opportunity[] lOp = [Select ID,OrderNumber__C from Opportunity where Id = :a.OpportunityId]; --> Select opportunity
if (lOp[0].OrderNumber__C!='NULL'){ --> If Ordernumber is not NULL show alert
a.addError('ALERT!!!');
}
}
}
}
First of all I want to say I'm new with Force for Eclipse.
When i'm trying to test this class, Eclipse returns 'line not covered' warning.
I tried it on develop and it works, then when I want to pass the test in order to deploy it to production, all turns in a strange mess...
Why those warnings? Even if only leave the class with a simple method it returns warnings... Anyone can tel me what I'm doing wrong.
Thanks :)
... the code:
public class Test_Class {
public static void checkOrderNumber(OpportunityLineItem[] accs){ --> Waits for a table results
for (OpportunityLineItem a:accs){ --> For items on the table received...
Opportunity[] lOp = [Select ID,OrderNumber__C from Opportunity where Id = :a.OpportunityId]; --> Select opportunity
if (lOp[0].OrderNumber__C!='NULL'){ --> If Ordernumber is not NULL show alert
a.addError('ALERT!!!');
}
}
}
}
You did write test methods for your code right ? (if you didn't, go to the Apex manual and read that first) -> all code you write needs to be tested by test code. Clicking on the 'test' button in the SFDC interface doesn't count as 'testing'
The idea is that your test classes simulate a 'run' over all your lines of code to make sure that everything works as expected.
If you have 'line xx not covered' then that means that your test class did not simulate enough different calls and situations to run all of your code at least once and it will mention what code was not covered by your test code.
David
I made my testMethod but now I got this problem... :(
The method I want to test called checkOrder waits for a Opportunity object who is sent by a call in a before update trigger.
I try to simulate this on my testMethod but obviously I'm not doing this well 'cause in the call to checkIntranetOrder inside my test method the for condition never begins.
What I'm doing wrong? What is the way to simulate the pass of a Opportunity object as sent by a trigger.new or trigger.old?
Thanks in advance
The code:
public static testMethod void TestcheckIntranetOrder() {
Opportunity[] lOp = [Select Id,Order__c from Opportunity where Id = '006R000000286W2']; --> Make a Opportunity whit the values I need
chekOrder(lOp); --> Call chekOrder Method
}
public static void checkOrder(Opportunity[] accs){
for (Opportunity a:accs){ --> Want a opportunity
if (a.Order__c!=NULL){
a.addError('Alert');
}
}
}
}
Using a <list>
List<Opportunity> leads = new List<Opportunity>();
leads.add(new Opportunity(Order__c='12332'));
checkOrder(leads);
Thanks ! :)
Good to hear.
I didn't see it in the snippets of code you provide but you are using System.assertEquals( .. , ...) to check for 'expected values / behaviour' right ?
Also do the appropriate inserts/updates to fire of your triggers (if you have them). Don't worry : Objects saved in a testMethod will not 'really' be saved, it all rolls back once the test is finished.
Running the code is one thing, seeing if it does what it is supposed to do is another.
David