Developing (a.k.a. Testing) in Python - Part 1: Python and Java
Join the DZone community and get the full member experience.Join For Free
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.
Opinions expressed by DZone contributors are their own.