1

誰かがこのコードが私に何をしているのか説明できますか? 行の目的がわかりませんsystem.debug

Test.startTest();
// 1. First check to see if it's a brand new Owner ID
System.debug('first test'); // Creating a new opportunity to start Trigger
Opportunity newtestOpp1 = TestUtil.initOpportunity(TestUtil.initAccount(),TestUtil.initContact());
User testUser1 = TestUtil.initUser(); 
newtestOpp1.OwnerId = testUser1.Id;//setting OwnerId
System.debug('The opp owner should be null' + newtestOpp1.Op_Owner__c);
try{        
    insert newtestOpp1;
} catch ( DMLException d ) {
    System.debug(d);
}
System.debug('The opp owner should not be null' + newtestOpp1.Op_Owner__c);
4

1 に答える 1

1

Op_Owner__c商談レコードの挿入時に、ある種のワークフローまたはトリガーがフィールドに値を設定しているかどうかをテストすることになっているように見えます。ただし、テストがアプリケーションの機能を実際に検証することを意図している場合、デバッグ ステートメントは実際にはSystem.assertorである必要があります。System.assertEquals通常、デバッグ ステートメントは、テスト ケースの実行中には表示されません。

Op_Owner__cこれは、デバッグ ログに何かを出力するだけでなく、実際にフィールドの値 (テスト ケースの目的) についてアサーションを行う、クリーンアップされたバージョンです。

Test.startTest();
Opportunity newtestOpp1 = TestUtil.initOpportunity(TestUtil.initAccount(),TestUtil.initContact());
User testUser1 = TestUtil.initUser(); 
newtestOpp1.OwnerId = testUser1.Id;//setting OwnerId
System.assertEquals(null, newtestOpp1.Op_Owner__c, 'The opp owner should be null');
try{        
    insert newtestOpp1;
} catch ( DMLException d ) {
    System.debug(d);
}
System.assertNotEquals(null, newtestOpp1.Op_Owner__c, 'The opp owner should not be null');
于 2013-06-05T20:57:07.780 に答える