Eclipse integrates the JUnit framework to enable seamless test integration in Java, and Python is a great language for writing tests. Learn how to write Eclipse JUnit tests in Jython (Python for Java).
by Laurent Ploix
Amaury Forgeot d'Arc
Dec 14, 2004
Page 1 of 4
he Python language has a few characteristics that make it great for unit testing:
It integrates very well with the platform it runs on, so you can write tests that will run on every platform. For example, Jython integrates Python and Java; the Win32 extension fully integrates Python into COM objects, and so on. For large organizations, this flexibility in a single language saves a lot of time.
Python now has several testing paradigms and some great tools to perform the tests. To my mind, the most effective is to put the tests inside code comments ("doctests"), but this article focuses on another one: unittest, which is very close to JUnit from the Java space.
Python is quite straightforward because of dynamic typing (variables accept any type) and natural introspection. Coding in Python requires very few lines of code, and you don't need to catch any specific exceptions. On top of that, you can write your tests before you code, because your testing code is not linked to your tested code. You can even make your tests part of your specifications if you really want to, which is not as easy to do so with compiled languages.
JUnit is one of the best-known Java testing frameworks. Eclipse 3.0 actually integrates a JUnit plugin. I use the continuous testing plugin, which enables me to test the code against a JUnit set of tests each time it compiles.
This article explains how to write Jython tests in an Eclipse/JUnit/continuous testing programming environment. It demonstrates setting up an environment with a simple class to test through a JUnit test case, and then adding a Jython test case that you can integrate seamlessly into the Eclipse JUnit view.