Back to TTCN-3 Refactoring Catalog

Add Explaining Log

Add explanatory log statements where verdicts are changed.

Motivation

A problem often occurring is that the tester does not know what went wrong when a test case fails. This is especially the case when a test case can fail due to several reasons (e.g. an unexpected message arrived, the message content is unexpected, a timeout occurs) and the implicit logging is not sufficient. Therefore, it is recommended to add logging statements to the code that make it easier to comprehend why a test case failed. As a result, less time is spent for analyzing test case verdicts.

Mechanics

  • Find code locations in the source (source locations) where the verdict is changed to fail or inconc.
  • Add an explanatory log statement before the verdict change is performed which gives the tester sufficient information on why the verdict is changed. Repeat this step for all source locations.
  • Compile and validate.

Example

In the following listing, the alt statement contains typical error handling where unexpected messages or timeouts lead to a failed test case verdict. However, when this test suite with this test case is executed and the test case fails, there is no possibility to know if the reason was an expected message or a timeout. Hence, log statements are added.

testcase tc_exampleTestCase() runs on ExampleComponent {
	timer t_guard;
	// [...]
	t_guard.start ( 10.0 );
	alt {
		[] pt.receive( a_MessageOne ) {
			pt.send( a_MessageTwo );
		}
		[] any port.receive { 
			setverdict( fail ); 
			stop;
		}
		[] t_guard.timeout { 
			setverdict( fail ); 
			stop;
		} 
	}
}

After applying the Add Explaining Log refactoring, the setverdict statements are explained through a log statement before them.

testcase tc_exampleTestCase() runs on ExampleComponent {
	timer t_guard;
	// [...]
	t_guard.start ( 10.0 );
	alt {
		[] pt.receive( a_MessageOne ) {
			pt.send( a_MessageTwo );
		}
		[] any port.receive { 
			log("tc_exampleTestCase: unexpected message received."); 
			setverdict( fail ); stop; 
		}
		[] t_guard.timeout {
			log("tc_exampleTestCase: no messages received in time."); 
			setverdict( fail ); stop; 
		} 
	}
}

Back to TTCN-3 Refactoring Catalog