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
December 14, 2004
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.
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!