Dan is co-founder of Fiesta - https://fiesta.cc. Before Fiesta, he was a developer working on ShopWiki. Daniel is a DZone MVB and is not an employee of DZone and has posted 8 posts at DZone. You can read more from them at their website. View Full User Profile

Developing (a.k.a. Testing) in Python - Part 1: Python and Java

  • submit to reddit

Before coming to Fiesta I had worked with Java almost exclusive for the past six years. The codebase at my previous company was about 2,000 files and 300,000 LOC. I’m fairly fluent in Java, but I’ve also been a longtime Python advocate; I was excited to jump into a larger, more collaborative Python project than what I’ve put together over the years.

I’d like to take some time to talk about how the experience has gone so far. In this post, I’ll share my thoughts on testing in Python:

Running test cases is Python’s version of compile-time checking.

Running our collection of tests (using nose) on a bunch of symbol changes (e.g. changing variable names or method signatures) often leads to a bunch of errors and failures. At the same time, refactoring some code in a large Java project could easily produce hundreds of compile errors. Comparing the time spent getting tests to pass versus getting Java code to compile, it feels like a push. However, when comparing my confidence that things are working, Python comes out ahead.

This confidence through testing is only possible because of Fiesta’s extensive set of test cases; there are more LOC in the test files than in the application itself. Our testing goal isn’t to test every method, but rather to cover all of the actions a user can take. In that vein, almost all tests are end to end.

I find it more natural to write tests in Python than in Java. With Java and other compiled languages, I typically feel that once I get something to compile, it will work. That’s rarely the case, but that feeling subtly influences me to not write testing code alongside the logic code. When writing for Python, I’m often using the interpreter and generally find myself wanting to save my progress. It just makes sense to piece things together in a test function and place asserts when I want to pin logic into place.

Given my experiences so far, I’m not sure if developing in Python is any faster or slower than doing so in Java, but the time is definitely spent on different things. I’d like to do some more posts on this topic in the future, so let me know your thoughts/questions in the comments.

Party On.



source: http://blog.fiesta.cc/post/11060794329/developing-a-k-a-testing-in-python

Published at DZone with permission of Daniel Gottlieb, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Otengi Miloskov replied on Mon, 2011/11/14 - 8:04pm

I hear you,
Lets put it simple, Takes same time to develop in java doing few tests and living with the compiler than with python or ruby doing the full tests comparable to a java with the compiler.

I like Python but everytime I go back to Java. Try Scala, type inference, lambdas and all out of the box but with the static of Java and compiler, Scala tests are nice, multicore, actors and many more goodies. Scala is much better of what it is right now, it can beat java and dynamic languages plain and simple.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.