Jun 3, 2008

Running Sharpen Tests


If you start using sharpen, you'll probably find some limitation / bug and, maybe, want to take a look into the issue.

In this case the best approach (IMHO) would be to i) start a discussion in Sharpen Forum and, if
appropriated (in the case there's no issue filed already), ii) file a new Jira issue into our issue tracking system.

Next, if you have the time, iii) try
to replicate the behavior with a minimal test case. The last step iv) would be trying to fix the issue.

This post is all about iii, or to be more clear, on how to run / write unit tests for Sharpen.

Let's start by opening an empty eclipse workspace:

Next, open SVN perspective and add a new SVN repository pointing to


and checkout all projects.

No install the plugin (as explained here):
  • In package explorer (Java perspective), right click on sharpen.core and select "Export" from the context menu.

  • Expand the "Plug-in Development" folder and select "Deployable plug-ins and fragments".

  • Set "Destination" to the root folder of your eclipse installation and click "Finish";
Now you can run Sharpen Tests by right clicking on "sharpen.ui.tests" and selecting "Run as / JUnit Plug-in Test";

after some processing your screen should look something like:

When the tests finishes you should see 0 (zero) errors and failures (as of today, there's some issue with sharpen.builder and sometimes you will get 2 errors in its tests but these errors don't prevent sharpen to work properly and, as you can see, when I executed the tests the errors didn't showed up).

Now let's explore the general look 'n' feel of a Sharpen test. In package explorer expand the node sharpen.ui.tests then testscases.

For each sharpen functionality there will be at least one pair of files (collectively called Test Case Resource):
  • One .java.txt that stores the java source to be converted;
  • One .cs.txt storing the expected sharpened file;
In the above picture we are testing interface conversion. Take the time to poke around testcases folder checking some of the tests.

The next logical step is to add new tests. Basically to add a new tests we need to:
  1. Create the original java source (.java.txt)

  2. Create the expected cs file (.cs.txt)

  3. Plug these two files into the test engine. In the common scenarios, all we have to do is to call runResourceTestCase() function.

To see an example, just expand sharpen.ui.tests/src/sharpen.ui.tests folder and double click on NativeInterfacesTestCase.java.

In a future post (soon I hope) I want to take a look in a few other points such as:
  • Getting a little better performance when starting sharpen using the approach presented in this post.
  • How to debug sharpen.
  • A trick to see the expected / actual values (useful when creating new tests).



Mihran Shahinian said...

The svn location in your article does not work. This one from db4o seems to work https://source.db4o.com/db4o/trunk/sharpen/

Vagaus said...


Thanks for letting me know about the link! Probably I was sleeping when I typed it :)

It's fixed by now