You need to sign in to do that
Don't have an account?
sai_lavu
@future annotations and unit testing
Hi,
I have the following method in a class called Project, which summarizes Opportunities linked to the custom Project object.
The unit test below is failing. If I remove the @future annotation the test passes. Is this expected behaviour or is it a bug?
I have the following method in a class called Project, which summarizes Opportunities linked to the custom Project object.
Code:
@future public static void updateSummaryFromOpportunities(List<Id> projectIds) { if(projectIds == null || projectIds.size() == 0) throw new InvalidParameterException('No Projects provided.'); ... }
The unit test below is failing. If I remove the @future annotation the test passes. Is this expected behaviour or is it a bug?
Code:
static testMethod void testUpdateSummaryFromOpportunities_CheckParam() {
try {
Project.updateSummaryFromOpportunities(null);
} catch(InvalidParameterException e) {
System.assertEquals('No Projects provided.', e.getMessage());
}
}
When you are calling this method in sync, you are catching the exception and asserting.
Future methods are called latter from a different thread and it is not a good idea to throw exception from them.