You need to sign in to do that
Don't have an account?
KhaledZero
Unit test I cannot exceed 60%
Hi,
I want be at least 75 % of cover of the code of my class
My class to be tested :
Public static void blockChange(FeedItem item){ List<CollaborationGroup> MyGroup = [Select Name From CollaborationGroup where Id = :item.ParentId LIMIT 1]; if(MyGroup.size() >0){ if(MyGroup.get(0).Name.toUpperCase().contains('#INACTIF')){ item.addError('this is inactive group'); } } } Public static void blockChange(FeedItem item, FeedComment comment){ List<CollaborationGroup> MyGroup = [Select Name From CollaborationGroup where Id = :item.ParentId LIMIT 1]; if(MyGroup.size() >0){ if(MyGroup.get(0).Name.toUpperCase().contains('#INACTIF')){ comment.addError('this is inactive group'); } } } }
My Test Class:
@isTest(SeeAllData=true) public class InactiveGroups_ClassTest{ static testMethod void myUnitTest() { Group gp= new Group(); gp.Name ='#inactif'; FeedItem item = new FeedItem(); item.ParentId = gp.Id; FeedComment comment = new FeedComment(); Test.startTest(); InactiveGroups_Class.blockChange(item); InactiveGroups_Class.blockChange(item, comment); Test.stopTest(); } }
Thx.
All Answers
can you post your full class code?
first of all remove that "void" and return something as i have done below, coz statci method can be called easily,
and after that simply call these methods and in only two lines your code coveerage will be 100%, like
//insert your item record first
insert iten;
//call your static method here
className.blockChanges(item);
Hi,
Try to use below test class code.
Test class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
@hitesh90
it's now at 30%
:(hye Abhi,
can you give me more explacation or code to teste please
thank you
Try to use following code.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
it's the same thig with my code !
the resulte 60%