You need to sign in to do that
Don't have an account?
Any help would be great for a beginner
I'm currently working throught the Force.com work book.
But i getting a failure when i run the test, It errors on line 68 '"column 6External entry point"
have highlighted the line, any help would be great.
@isTest
private class MileageTrackerTestSuite {
static testMethod void runPostiveTestCases() {
Double totalMiles = 0;
final Double maxtotalMiles = 500;
final Double singletotalMiles = 300;
final String createdbyId = UserInfo.getUserId();
List<Mileage__c> deleteMiles = new List<mileage__c>();
// Data clean-up
System.debug('Setting up testing - deleting any mileage records for today');
deleteMiles = [SELECT miles__c from Mileage__c WHERE createdDate = TODAY
and createdById = :createdbyId];
if(!deleteMiles.isEmpty()){
delete deleteMiles;
}
// Positive tests
System.debug('Insert 300 more miles...single record validation');
Mileage__c testMiles1 = new Mileage__c(Miles__c = 300, Date__c = system.today() );
insert testMiles1;
// Validate single insert
for (Mileage__c m:[SELECT miles__c FROM Mileage__c
WHERE createdDate = TODAY
and createdById = :createdById
and miles__c !=null]) {
totalMiles += m.miles__c;
}
System.assertEquals(singletotalMiles, totalMiles);
totalMiles = 0;
// Validate bulk insert
System.debug('Insert 200 more miles...bulk validation');
List<Mileage__c> testMiles2 = new List<Mileage__c>();
for(integer i=0; i<200; i++){
testMiles2.add( new Mileage__c(Miles__c = 1, Date__c = System.today()));
}
insert testMiles2;
// Assert Mileage
for(Mileage__c m:[SELECT miles__c from Mileage__c
WHERE createdDate = TODAY
and createdById = :createdbyId
and miles__c != null]) {
totalMiles += m.miles__c;
}
system.assertEquals(maxtotalMiles, totalMiles);
}
// Negative tests
static testMethod void runNegativeTestCases(){
system.debug('Inserting 501 miles...negative test cases');
Mileage__c testMiles3 = new Mileage__c(Miles__c = 501, Date__c = system.today());
// Assert Error Message
try{
insert testMiles3;
} catch (DmlException e) {
// Assert Error Message
system.assert(e.getMessage().contains('Insert Failed. '+
'First exeception on row 0; first error: '+
'FIELD_CUSTOM_VALIDATION_EXCEPTION, '+
'Mileage request exceeds daily limit(500): [Miles__c]'),
e.getMessage());
// Assert Field
system.assertEquals(Mileage__c.Miles__c, e.getDmlFields(0)[0]);
//Assert Status Code
system.assertEquals('FIELD_CUSTOM_VALIDATION_EXCEPTION',e.getDmlStatusCode(0));
}}}
Is it throwing an error because the assert is failing? I.e. the exception doesn't contain the exact set of characters that you have specified?