You need to sign in to do that
Don't have an account?

write test class for Case to CaseComment
I have created a class that links a case with the case comment for a visualforce page but for the life of me I cannot remember how I write a test class for the apex class.
The class I require tests for is:
The test Class I have written is:
The code coverage does not seem to increase. Can anyone advise where I have gone wrong.
The class I require tests for is:
public class Caselinktocomment { public CaseComment comment { get; set; } public String commentText {get; set;} public String PublicPrivateAction {get; set;} public Caselinktocomment(ApexPages.StandardController stdController) { this.comment = new CaseComment(ParentId = stdController.getId()); } public PageReference saveComment() { insert comment; return null; } }
The test Class I have written is:
@istest Private class Caselinktocommenttests { static testmethod void createtestdata() { Id RecordId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Service_Desk').getRecordTypeId(); Case tcase = new Case(); tCase.Status = 'New'; tCase.Description = 'This ticket has been created as a test'; tCase.Subject = 'Test Case'; tCase.RecordTypeId = RecordId; tCase.Reason = 'Access Requests'; tCase.Origin = '';Phone INSERT tCase; CaseComment tComment = new CaseComment(); tComment.ParentId = tCase.Id; tComment.CommentBody = 'Test Comment'; tComment.IsPublished = FALSE; tComment.IsNotificationSelected= FALSE; Test.startTest(); INSERT tComment; Test.stopTest(); system.assertEquals(1, [SELECT count() From CaseComment], 'Test Comment'); } }
The code coverage does not seem to increase. Can anyone advise where I have gone wrong.
I hope you are doing well .....!!
Please use the below code:
Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.
Thanks & Regards,
Foram Rana
All Answers
I hope you are doing well .....!!
Please use the below code:
Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.
Thanks & Regards,
Foram Rana
That has worked brillantly!