1 st Workshop on Refactoring Tools ( WRT ' 07 )

Refactoring is not only useful for source code of implementations, but as well for test specifications. The open source TRex tool automates the application of refactorings and the detection of refactoring opportunities for test suites that are specified using the standardised Testing and Test Control Notation (TTCN-3). Depending on the refactoring, the behaviour preserving transformations may include syntax tree transformations and direct modification of the source code; for suggesting refactorings, metrics are calculated and code smell patterns are detected. Introduction. The Testing and Test Control Notation (TTCN-3) [1] is a mature standard from the telecommunication and data communication domain that is widely used in industry and standardisation to specify and execute test suites. Just like any other software artifact, tests suffer from quality problems [2]. To remove such quality problems from TTCN-3 test suites, we use refactoring [3]. For suggesting refactorings, we use a combination of metrics and code smell detection. In the following, we first present our approach for the quality assessment and improvement of TTCN-3 test suites. Subsequently, the TTCN-3 Refactoring and Metrics Tool TRex and its implementation are described. Finally, future work is discussed in the outlook. Refactoring, Metrics, and Code Smell Detection for TTCN-3 Test Suites. Refactoring of test suites has so far only been studied in the context of JUnit [2]. Thus, we have developed a refactoring catalogue for TTCN-3 [4, 5] which includes 23 refactorings using language specific concepts of TTCN-3. Furthermore, we found 28 refactorings from Fowler’s Java refactoring catalogue [3] to be applicable to TTCN-3. For being able to automatically identify locations in source code where a refactoring is worthwhile, we investigated corresponding TTCN-3 metrics and TTCN-3 code smells. For example, a Number of References metric is used to identify definitions that are never referenced and can thus be removed or that are referenced only once and can thus be inlined using a corresponding refactoring. Even though we experienced that metrics are able to detect various issues, they are not sophisticated enough to detect more advanced problems. Therefore, we investigated pattern-analysis of source code and as a result, we have developed a catalogue of TTCN-3 code smells [6]. So far 38 TTCN-3 code smells have been identified. TRex Implementation. To automate refactoring for TTCN-3 test specifications, we have implemented the open source TTCN-3 Refactoring and Metrics tool TRex [4]. The initial version has been developed in collaboration with Motorola Labs, UK [7]. TRex implements state-of-the-art editing capabilities, assessment and improvement techniques for TTCN-3 test suites based on the calculation of metrics, automated smell detection, and refactoring. TRex is based on the Eclipse Platform [8] and thus makes use of the infrastructure offered, e.g. the Language Toolkit (LTK) or the Eclipse Test & Performance Tools Platform (TPTP) static analysis framework. The analysis infrastructure including lexer, parser, symbol table, pretty printer, etc. for TTCN-3 have been implemented using ANother Tool for Language Recognition (ANTLR) [9]. The automated refactorings we currently provide concentrate mostly on the improvement of test data descriptions (TTCN-3 templates). The refactoring implementations can be applied in two different ways: either the test developer invokes the refactoring from the code location 1st Workshop on Refactoring Tools (WRT'07)