Tag Archives: eclipse

Eclipse and TestNG

I was playing around with Eclipse and TestNG, the thing you need/want to do is, after you have installed testng via de Eclipse market place and restart Eclipse to go to the project build path.

So right click the project and select from the popup menu Build Path » Configure Build Path...

In this window, make sure you have selected the Libraries tab in the right-hand side of the window.

Next select Add Library... and from the resulting window that pops up select TestNG (or JUnit).

When you select Next or Finish (depending whether you picked TestNG or JUnit), you will then see TestNG under the JRE System Library entry as another library entry. If you expand this you see the testng.jar being included and pointing to the right jar file that’s in Eclipse’s plugins directory.

When you now press OK you should see the imports getting resolved.

You will need to remove any external jar dependencies for TestNG or JUnit of course, because it’s double and will most likely lead to problems.

Now, when you go to Run » Run Configurations... you see a TestNG (JUnit) entry. When you select that entry and create a new configuration underneath it, it should already resolve everything you need (classes, packages, and so on).

Oh, do keep in mind that you will have to mark the test folder as a source folder for it all to work. Right click the folder, select Build Path » Use as Source Folder.

Setting up Eclipse 4.2 as I like it

Download Eclipse 4.2 Classic 64-bits version from the Eclipse website. Extract the contents to a location, such as C:\Eclipse. Adjust the eclipse.ini in that directory according to my post in order to pin it to the taskbar.

Next, within Eclipse, go to Window » Preferences » Install/Update » Available Software Sites » Add... and add the following URL under something like “4.2-M builds”: http://download.eclipse.org/eclipse/updates/4.2-M-builds. After adding you can hit Reload to reload the information from the website. Exit all windows through pressing OK. Then follow up by going to Help » Check for Updates and you will most likely get an Eclipse SDK update right away. Accept the licensing terms and wait until it downloaded and installed everything and restart Eclipse.

Go to Help » Install New Software... » Work with, select the Juno entry and from the resulting list of software select General Purpose Tools » Marketplace Client followed by Next » Next, accept the license and Finish. Restart Eclipse when done. Now under Help is an entry called the Eclipse Marketplace.

Open the Eclipse Marketplace and search for and install the following: “code recommenders”, “MercurialEclipse”, “mylyn” (not selecting the Bugzilla connector). It might ask if it is OK to install unsigned content, acknowledge it.

Pinning Eclipse to the Windows taskbar

I pin programs that I use frequently to the taskbar of Windows. So I was a bit surprised to see that the newer version of Eclipse, Juno, doesn’t seem to support this by default. After some searching I find out that you can force this by adjusting the eclipse.ini by starting the file with something akin to:

C:\Program Files\Java\jdk1.7.0_05\bin

Then after starting Eclipse with this in place, you can, once fully loaded and past the splash screen, pin Eclipse to the taskbar.

Trac and Mylyn integration

At work we use Jira for some projects, but the projects I work on use Trac. For many projects an environment like Trac is sufficient. Recently I started to use Eclipse with Pydev for the Python development. Eclipse features a plugin called Mylyn, which allows you to configure a task repository and directly access the tasks in that repository. This is extremely useful, since the repository can also be an instance of Jira or Trac. To connect Mylyn to these repositories you will need a so-called connector. For Jira there’s the Atlassian Connector for Eclipse and for Trac the standard Eclipse repository already has a Mylyn Connector: Trac available. Make sure this is installed.

Next, we need to install some plugins for Trac. On my setup we use AccountManager for authentication and managing of the password files. To make Mylyn talk with Trac we need to add the XML-RPC as well as the HTTPAuth plugin. The XML-RPC plugin is the one that provides XML-RPC methods for Mylyn to talk with Trac. The HTTPAuth plugin is needed if your Trac’s login has been replaced by AccountManager (as is the typical way to use it). HTTPAuth forces certain URL paths (/xmlrpc, /login/xmlrpc) to use standard authentication.

A typical trac.ini will look like this after enabling the appropriate plugins:

password_file = /usr/local/projects/project1/svn-auth
password_store = HtPasswdStore
acct_mgr.admin.accountmanageradminpage = enabled
acct_mgr.api.accountmanager = enabled
acct_mgr.htfile.htpasswdstore = enabled
acct_mgr.web_ui.accountmodule = enabled
acct_mgr.web_ui.loginmodule = enabled
acct_mgr.web_ui.registrationmodule = disabled
httpauth.* = enabled
trac.web.auth.loginmodule = disabled
tracrpc.* = enabled
paths = /xmlrpc, /login/xmlrpc

After restarting Apache (with mod_wsgi, of course), if you go to http://trac.example.com/project1/xmlrpc it should present you with a user/password prompt. But most likely this will keep repeating without authorising you. After a bit of head scratching and looking around I found out that that is because mod_wsgi requires to pass authorization through to the WSGI application by means of WSGIPassAuthorization On in the appropriate Apache configuration file.

After all this works, you can configure a new Mylyn repository within Eclipse (Windows > Show View > Other > Tasks > Task Repositories). If you then click the icon that stands for create new repository it will present you with a configuration window for adding new repositories. Select the Trac option, followed by Next. In the Server field you can just add http://trac.example.com/project1, followed by a, for you, descriptive Label for this repository. The User ID and Password are those you use to log into the Trac instance. Under Additional Settings is an option for selecting the Access Type, make sure you select XML-RPC here. Ensure that Task Editor Settings has TracWiki selected. Now, by selecting Validate Settings, you ought to see a message stating “Authentication credentials are valid” at the top of the window.

That’s it. You can now follow the Mylyn User Guide.