Developing (a.k.a. Testing) in Python - Part 1: Python and Java
![]() | This content is part of the Python Zone, which is presented to you by DZone and New Relic. Visit the Python Zone for news, tips, and tutorials on the Python programming language. provides the resources and best practices to help you monitor these applications. |
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.
Dan
source: http://blog.fiesta.cc/post/11060794329/developing-a-k-a-testing-in-python
![]() | Python is a fast, powerful, dynamic, and versatile programming language that is being used in a variety of application domains. It has flourished as a beginner-friendly language that is penetrating more and more industries. The Python Zone is a community that features a diverse collection of news, tutorials, advice, and opinions about Python and Django. The Python Zone is sponsored by New Relic, the all-in-one web application performance tool that lets you see performance from the end user experience, through servers, and down to the line of application code. |
- Login or register to post comments
- 2436 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)
Comments
Otengi Miloskov replied on Mon, 2011/11/14 - 8:04pm
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.