I am certainly guilty of doing way too much work manually instead of writing short scripts to automate it. Of course if I am not familiar with the available tools it may be faster to do it by hand as I need to learn and try. But learning a bit about the system is the more valuable approach in the long run.
I have a bunch of test classes in a package for which I would like to add a single parent class.
So let’s first add the new parent class (for now as a subclass of
From the browser we can see that all the classes are in the
XMI-Analyzer package and
Tests tag, so let’s find a way to access that.
To access packages, you can ask the
RPackage class for the
RPackageOrganizer singleton and finally for the package itself. Punch it into playground and go.
We can go deeper through the inspector and see what we have available there.
If you also explore the available methods you can find a lot of convenience methods, so we can just type in this
Now all we have to do is select classes that inherit directly from
TestCase and change their parent to
Finally we must change the parent class of the
XMIBaseTest itself (since we’ve created it as a subclass of
Object to avoid filtering it here).
Note that you don’t need intermediate variables, but they make for much easier debugging and inspecting.
And we are done! The
Hier. (Hierarchy) button shows you all the ancestors and descendants of the selected class.
Of course in this particular case it may just be faster to do it by hand. But if I don’t know what tools I have available, how can I possibly decide which approach is better? A similar question arose when I wanted to change class prefixes, and doing it automatically is certainly the way to go there.