I have only 73% code coverage, however, I've created multiple tests, all which pass.
Here is the controller code:
public class CaseController {
public ApexPages.StandardController stdCntrlr {get; set;}
public CaseController(ApexPages.StandardController controller) {
stdCntrlr = controller;
}
public Case cs{get; set;}
// public CaseController(){
// cs = new Case();
}
public PageReference save(){
if(cs != null) {
// upsert cs;
} else {
stdCntrlr.save();
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.CONFIRM,'Successfully inserted Case.'));
PageReference pr = new PageReference('/apex/CasePage');
pr.setRedirect(true);
return pr;
}
// return null;
}
}
This is my test class
public class CaseTest {
static testMethod void testMethod1(){
Case testCase = new Case();
testCase.Status = 'New';
testCase.Origin = 'Phone';
testCase.Subject = 'test';
testCase.Description = 'test';
insert testCase;
Test.startTest();
ApexPages.StandardController sc = new ApexPages.StandardController(testCase);
CaseController testCasePage = new CaseController(sc);
PageReference pageRef = Page.CasePage;
pageRef.getParameters().put('id', String.valueOf(testCase.Id));
Test.setCurrentPage(pageRef);
testCasePage.save();
Test.stopTest();
}
static testMethod void bulkTestMethod2(){
test.StartTest();
integer caseCount = 0;
list<Case> cs = new List<Case>();
while (caseCount<=151){
caseCount +=1;
}
insert cs;
test.stopTest();
}
static testMethod void positiveTestMethod3(){
test.startTest();
Case cs = new Case(Status = 'New');
system.assert(Database.insert(cs).isSuccess());
test.stopTest();
}
static testMethod void negativeTestMethod4(){
test.startTest();
Case cs = new Case();
cs.Status = Null;
insert cs;
Database.SaveResult sr = Database.insert(cs, false);
system.assertEquals(false, sr.isSuccess());
}
}
The lines with "//" is what is not covered in the test. I dont know why it doesnt cover those lines when Ive created a test class in which creates and inserts a new Case.