+ Start a Discussion

MileageTracker Negative Test Case



I posted this in the newbies forum too. Apologies if I have broken any protocols but I am really stumped with this and as you may imagine, when learning a new technology it is quite important that any examples work as expected.


The problem I have is that I don't know if it's something I have done or simply because the negative test cases doesn't work in the example?


First of all here is the code I'm talking about - it's in the testing section of the MileageTracker - Negative Test Case.



static testMethod void runNegativeTestCase() 
  		System.debug('Inserting 501 miles... negative test case');
  		Mileage__c testMiles3 = new Mileage__c(Miles__c = 501, Date__c = System.today());
  			insert testMiles3;
  		} catch (DmlException e)
				  			//Assert Error Message  
				   System.assert(e.getMessage().contains('Insert failed. First exception '+
				      'on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, '+
				      'Mileage request exceeds daily limit(500): [Miles__c]'), 
				//Assert Field  
				   System.assertEquals(Mileage__c.Miles__c, e.getDmlFields(0)[0]);
				//Assert Status Code  



The problem I have is that when I run the test I get the following - see linked image...


Negative Test Case Mileage Tracker



Thanks in advance for your help.


Kind regards,





Ok, so not sure why I couldn't post an image but here is a link to the image showing what I see in my Force.com IDE...



Error Example