2013-06-05 2 views
1

누군가이 코드가 내게 무엇을하고 있는지 설명 할 수 있습니까? 나는 system.debug 라인의 목적을 이해하지 못한다. 이 워크 플로우 또는 트리거 어떤 종류의 기회 기록을 삽입시 Op_Owner__c 필드에 값을 설정 여부를 테스트해야하는데 같은여기에이 테스트 케이스의 목적은 무엇입니까?

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); 

답변

1

나에게 보인다. 테스트가 실제로 응용 프로그램 기능을 확인하기위한 것이라면 디버그 문은 실제로 System.assert 또는 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'); 
관련 문제