The Artima Developer Community
Sponsored Link

SuiteRunner Forum
jython test scripts instead of java

11 replies on 1 page. Most recent reply: Oct 9, 2005 11:54 PM by presanv sanv

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 11 replies on 1 page
Clark Updike

Posts: 11
Nickname: clark
Registered: Apr, 2002

jython test scripts instead of java Posted: Feb 27, 2003 8:36 AM
Reply to this message Reply
Advertisement
I haven't yet used a unit test framework. My gut feeling is that it would be much easier to write unit tests using a scripting language rather than java. Since jython runs java (actually runs python in a jvm), it is an obvious choice. Can anyone tell me why this would not be a good approach? The benefit is that I could crank out tests much faster with a significantly smaller (and easier to maintain) test code base.


I haven't looked at SuiteRunner's api but I'd guess it would not be too difficult to integrate a jython interpreter to run jython test scripts. Also, you'd get the benefit of developing your tests with the aid of a command line interpreter.


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: jython test scripts instead of java Posted: Feb 27, 2003 2:19 PM
Reply to this message Reply
> I haven't yet used a unit test framework. My gut feeling
> is that it would be much easier to write unit tests using
> a scripting language rather than java. Since jython runs
> java (actually runs python in a jvm), it is an obvious
> choice. Can anyone tell me why this would not be a good
> approach? The benefit is that I could crank out tests
> much faster with a significantly smaller (and easier to
> maintain) test code base.
>
In my interview with Guido van Rossum, he mentioned that he knows of Java people who use Jython for test-driving their Java apps. The discussion of Jython is about a third the way down this page:

http://www.artima.com/intv/strongweak3.html

My impression was he was talking about trying things out quickly, which is a useful thing. But I think JUnit and SuiteRunner are geared more towards buildings tests that stick around, either unit tests that become part of the build, or conformance test kits that become part of an API standard.

>
> I haven't looked at SuiteRunner's api but I'd guess it
> would not be too difficult to integrate a jython
> interpreter to run jython test scripts. Also, you'd get
> the benefit of developing your tests with the aid of a
> command line interpreter.

We like Python around here, so we'll think about this. But one thing you certainly can do, as far as I know, with Jython is write Jython code that you compile to Java bytecodes. If I am correct about that, then you can write your Suites and test methods in Jython, not Java. I haven't tried that, but it would be fun to try.

Clark Updike

Posts: 11
Nickname: clark
Registered: Apr, 2002

Re: jython test scripts instead of java Posted: Feb 28, 2003 4:13 PM
Reply to this message Reply
I searched for jython unit testing framework but didn't find one (of course, pyunit is out there).

Although some think jython/python is only suitable for tinkering/disposable code, the system I work on has a lot of functionality implemented in jython running on the server--and it will only increase in time.

The only problem I see with having a large test suite in jython is that there are no 'refactoring' IDE's for jython so you'd have to do a manual synchronization when you change package/class/method names or signatures. I'm still hoping someone will write the Eclipse jython module (sigh).

I have used jythonc to generate class files but is does complicate things a bit, adds extra steps, requires more training, etc.

In looking at the SuiteRunner source, I think I could subclass Suite and override execute() to use a jython interpreter and to expect to load the jython file in a standardized way (relative to the concrete Suite subclass). Let's call this subclass, JythonSuite. Then, to create a jython test, I would create a trivial subclass of JythonSuite (let's call this MyJythonSuite, basically a do-nothing-different override) and put the jython file in the same directory with the name MyJythonSuite.py. Then, JythonSuite could use the MyJythonSuite object to find the jython file in the same directory (via the object's getClass().getResourceAsStream().

I'll try taking a shot at this.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: jython test scripts instead of java Posted: Mar 1, 2003 1:40 AM
Reply to this message Reply
I'm curious why you don't want to just create a Jython class that extends Suite and add test methods. I guess you don't want the compile step?

Anyway, what you describe sounds like a good reason to override execute. But I assume you'll want to also do dynamic discovery of test methods on the loaded Jython class and invoke them, passing reports to the Reporter? I'm not sure how you'd do sub-Suites.

Let us know how it works out. When we get a moment, Matt and I want to play around with Jython and SuiteRunner too.

Clark Updike

Posts: 11
Nickname: clark
Registered: Apr, 2002

Re: jython test scripts instead of java Posted: Mar 1, 2003 10:55 PM
Reply to this message Reply
I figured I'd try it the way you thought most obvious (jythonc). I wrote your AccountSuite.java as JythonAccountSuite.py and jythonc'ed it. After some trial and error, I eventually got it to compile through to completion. But I couldn't get SuiteRunner to run it. After inspecting the generated JythonAccountSuite.java, I observed that it extends Object not Suite. In fact, the java file makes no reference to Suite anywhere. I can call instance methods of Suite in the jython environment from my python subclass so something is going wrong with jythonc. Now that I think of it, jythonc couldn't have known about suiterunner distribution jar (and I don't see how to tell it about it). Funny it doesn't throw an error. Oh well.

But assuming I could tinker around and get it compile correctly, I'm still not thrilled with the approach. You have fire up jythonc with all the correct parameters--I never could get all the output files to go exactly where I wanted. You have to supply the @sig tags since you adding new methods. You have to always work with python classes. I could never get this process spun up with our development team--many of whom don't know java but are capable of scripting in jython. If it came down to jythonc or java, I'd probably just stick with extending Suite in java. Therefore, I think I'll still pursue the other approach I mentioned.

p.s I don't mean to dis jythonc--I have used it successfully in the past. One look at the generated java and you have to respect who ever figured that translation out.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: jython test scripts instead of java Posted: Mar 1, 2003 11:57 PM
Reply to this message Reply
Clark, Thanks for the update. I was just talking to Matt about this tonight. We aren't familiar enough with Jython to really see the solution. Next week I'll be visiting Bruce Eckel, who is "enamored with Python" to quote a former student. Maybe he will be willing to join me in exploring Jython and SuiteRunner a bit. Let us know what you come up with by posting to this topic. I think it would be interesting to figure out a nice way to script tests for Java classes in Jython using SuiteRunner.

Clark Updike

Posts: 11
Nickname: clark
Registered: Apr, 2002

Re: jython test scripts instead of java Posted: Mar 3, 2003 9:30 PM
Reply to this message Reply
I have a first cut working--at least as much as I have tested works (Gee, I could really use a test framework to test this thing ;-) Guess I'll have to write JythonSuiteSuite.py when I get a chance. It is designed pretty much as I outline in my other post. I ran JythonAccountSuite using it and got identical results with AccountSuite.

I'd prefer to get it in front of someone else's eyes sooner than later. I don't want to polish it yet if it has structural problems. Would you like me to send it in?

It has:

JythonSuite.java -- a Suite subclass that uses a PythonInterpreter to run the jython test file

JythonSuite_Environment.py -- the jython environment that loads the test file and interacts with JythonSuite to run the tests

JythonSuiteRerunner.java -- like SuiteRerunner but modified for JythonSuite.java

To use it, you trivially subclass JythonSuite in 3 lines of code (just the package, an import and the class declaration--that't it). Then create the jython test file in the same directory as the JythonSuite subclass. The jython test file is written using the same textX() and testX(aReporter) and also can have the setUpFixture and tearDownFixture methods. And you have to get jython.jar on the classpath. All in all, it is much simpler than jythonc

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: jython test scripts instead of java Posted: Mar 4, 2003 12:15 AM
Reply to this message Reply
That's sounds great. I'd love to try it. Could you zip it up and email it to me at bv@artima.com, or put it up on the web and let people download it?

Clark Updike

Posts: 11
Nickname: clark
Registered: Apr, 2002

Re: jython test scripts instead of java Posted: Mar 6, 2003 5:40 AM
Reply to this message Reply
FYI--It's in your inbox. I sent it to you on the 4th.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: jython test scripts instead of java Posted: Mar 6, 2003 11:42 AM
Reply to this message Reply
Thanks I got it. I have been working with it this morning. Yesterday I had an article to finish and didn't have time to look at it.

Kevin Brown

Posts: 1
Nickname: kbrowna2w
Registered: Jun, 2004

Re: jython test scripts instead of java Posted: Jun 28, 2004 11:53 AM
Reply to this message Reply
Was wondering what the current status of these JythonSuite* files were... And what the current methods of writing test in jython these days might be.

presanv sanv

Posts: 1
Nickname: presanv
Registered: Oct, 2005

Re: jython test scripts instead of java Posted: Oct 9, 2005 11:54 PM
Reply to this message Reply
Could you please send me also the zip..i know its too late to ask.

Thanks
Presanv

Flat View: This topic has 11 replies on 1 page
Topic: Does artima suiterunner support Junit4 Previous Topic   Next Topic Topic: Unsupported major.minor version 48.0

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use