両方とも、1 つまたは複数のレコードを使用した「正常系のケースのテスト」と「異常系のケースのテスト」用のテストクラスで使用されます。
System クラス
System.assert と System.assertEquals を使用して、異常系のサンプルテストクラス (Sample Test Class) でテストを行いましょう。
static testMethod void runNegativeTestCases(){
User u3 = [select id from User where alias='tuser'];
System.RunAs(u3)
{
System.debug('Inserting a record with 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) );
} //catch
} //RunAs(u3)
000382121

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.