function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IanM1963IanM1963 

MileageTracker Negative Test Case

Hi,

 

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());
  		
  		try 
  		{
  			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]'), 
				         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));
				        
  			}
  	}

 

 

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,

 

Ian

 

IanM1963IanM1963

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

 

Thanks.