Test-Driven Code Search and CodeGenie
Test-Driven Code Search (TDCS)
The increasing amount of open source code has led software
developers to adopt informal practices of code search and reuse over
source code available on the Internet. We are currently developing an approach
that uses test cases as an interface for automating that process.
We call this approach Test-Driven Code Search (TDCS). In TDCS, test cases
serve two purposes: (1) they define the behavior of the desired
feature to be searched; and (2) they test the matching results for
suitability in the local context.
Figure 1. TDCS basic process

CodeGenie is an Eclipse plugin that performs
TDCS using Sourcerer. CodeGenie provides
functionality to automatically integrate and detach the chosen code
into the developer's existing project.
- ASE 2007 Demo Abstract [PDF]
- OOPSLA 2007 ACM Student Research Competition. (PDFs:
[Abstract],
[Poster])
- (Awarded the first prize in the competition)
- CodeGenie v. 1.0.0
for Eclipse Europa (Version 3.3.1.1, Build M20071023-1652) [JAR]
- Documentation DRAFT 1.0 [PDF]
We have a handful of examples to let you quickly get started with CodeGenie.
First download the
jar for the plugin
and the
sample examples .
Copy the jar into your Eclipse's 'plugins' folder. Launch Eclipse and switch
to a new workspace where you would like to play with CodeGenie.
Once you get to a workspace, Follow these steps:
- Go to menu: File > Import > Existing Projects into Workspace
Figure. Import Dialog

- Click Next, and click 'Browse' for 'Select archive file' in the next dialog.
This will prompt you to select for a valid archive, for which you should select
the 'codegenie-examples.zip' from the location where you downloaded it.
You'll see all our samples listed as Projects.
Figure. Import CodeGenie Samples from a single Zip File

- Click 'Finish' and you'll get all the sample projects loaded in your workspace:
Figure. Sample CodeGenie Projects

- After you have successfully imported these projects make sure that JUnit library
is included in the build path for all the sample projects. If its not included, you can
easily do that. Right click on a project in the package explorer, click 'Properties'
> 'Java Build path' > 'Libraries' > 'Add Library', and select JUnit from there.
- Before running CodeGenie on these projects, you might have to set the url for a
valid sourcerer server. For this open up the 'Preferences' dialog box
(In Europa click on the menu: Eclipse > Preferences) and enter a valid url
(sourcerer.ics.uci.edu/sourcerer) for sourcerer in the CodeGenie preference as shown below.
Please note that you do NOT need to append the url with any protocol (as http).
Figure. Setting the Preferences

- Your Eclipse environment is now set up to run CodeGenie. Select any test case class
from the Package Explorer, right click on it and you'll get the CodeGenie context menu item.
For details on how to proceed from here, we strongly recommend that you consult the
full documentation. For a quick overview please refer to
the section CodeGenie in Action. The
OOPSLA SRC poster is also a good
reference for a quick overview of how TDCS in CodeGenie works. And yes, you can also watch
some demo videos we made to see how cool CodeGenie is :)
Fixes for Some Common Problems
If your search operation does not result in anything in the search view, these steps might
help:
-
For a given project remove the current source folder from the build path, and add it again.
You can do this in the 'Java Build Path' section of the project propeties dialog box.
-
Disable 'Build Automatically' feature in eclipse. Clean the project with 'Start a build automatically'
enabled.
-
There also are options to make the queries more constraining or relaxed that affect the number
of results retrieved. You can play around with these by clicking on the various buttons and the menu
options in the upper right hand side of the Search view.
- Eclipse workspace with sample test cases used to search sample features
[ZIP]
- Demo 1 (zipped AVI) [ZIP]
- Demo 2 (zipped AVI) [ZIP]
- Demo 3 (zipped AVI) [ZIP]
Feedback
If you like or dislike Codegenie, we would like to hear about it. If you encounter any technical issues,
we'd be happy to help out. If you wrote some cool unit tests and found the feature using CodeGenie,
we would be delighted to hear about that. For all these you can email us at
sourcerer_AT_ics.uci.edu (please replace _AT_ with @).
This section provides a very brief overview of working with CodeGenie, for full details
please refer to the manual.
You'll get a CodeGenie context menu for every JUnit test case you have in your project
once you have set up CodeGenie properly.
Figure 2. CodeGenie's Search Menu

Since you start with a test case that are testing features you have not implemented
yet, clicking on the 'Search' menu item triggers a search for the implementation of
those features. The search results are presented in the CodeGenie's Search View as
follows.
Figure 3. CodeGenie's Search View

The search view lists all methods that possibly implements the features that you
were expecting to implement for which you wrote the test cases. From this view
you can preview the actual implementation, request for a 'slice' (that pulls in
all the dependencies but only those that are required into your workspace) and
'weave' in those slices into your project's workspace. The woven implementation
then can be tested with your test cases. If they don't work as expected or if
you want to choose another search result, you can easily 'unweave' the woven
code and repeat the process with another search result.
Disclaimer
The following information may be gathered whenever a search is performed using
CodeGenie:
- The Sourcerer code query related to the test cases used to search
- An anonymization of the user’s IP address
Committers: Otavio Lemos, Sushil Bajracharya, Joel Ossher and Crista Lopes
Contributors: Ricardo Morla, Pierre Baldi, Ellen Barbosa and Paulo Masiero