Micro Focus is now part of OpenText. Learn more >

You are here

You are here

Java vs. Python for test automation? Why Ruby is the better choice

public://webform/writeforus/profile-pictures/fritz.png
Michael Fritzius President, Arch DevOps, LLC
 

What's the top language for writing software test automation scripts? Your guess is as good as anyone else's, because there's no agreement on this. And that's unfortunate. You would think by now we testers would have settled the debate.

Java and Python at the top two candidates. However, this is a holdover from the way that code was tested in the past. Developers were tasked with creating their tests, so they wrote test scripts that used languages they already knew.

That's all well and good if you have developers testing, but these days, who has time for that?

Developers should be spending their time producing new code. Which means testers are in charge of the testing process. And that means they get to choose what language they use to write their test automation scripts.

For those who are up in arms about using the same language both to write and test, keep in mind that what you write for the web doesn't actually compile in that language. Whether you use Java or Python or .NET to create a webpage, you're ultimately creating HTML code.

So we've had this difference between front-end and back-end languages all along; we just didn't admit it. It's the same thing here, and this is why you need to use Ruby for writing test automation code. It's a solid alternative to either of the two big names. 

(To be clear, the version of Ruby I'm referring to here is just "regular" Ruby and not derivatives such as JRuby or CRuby. Ruby by itself does let you do some more "illegal" things as opposed to a compiled language.)

Ruby stands out as a specialized tool

Like Java and Python, which have their own strengths and preferred audiences, Ruby is a language that's very powerful for specific uses. For example, Python is great at gobbling up unsorted data caches and processing them efficiently. That's why it's popular in unstructured settings such as data science.

For its part, Ruby, because it's an array-based language, works particularly well with ordered datasets.

And you know what's an ordered dataset? A website. There's always a logical flow to the structure, and there's always a way to locate what you're looking for. Because Ruby is a language that works better for this specialized service, it makes sense to pull it out of the toolbox.

A Swiss Army knife may be okay for lots of different tasks, but when you really get down to it, you don't want your surgeon using one to take out your appendix. You want your doctor to use the right tool for the job. And because Ruby matches so well with what you're doing in test automation, it makes sense to use it.

Ruby has a short learning curve

New test automation professionals are trying to learn two things at once: what test automation is, and a scripting language. This is a compound problem. If you can remove some of the barriers, that will allow new testers to progress faster not only through their test backlog, but up the career ladder as well.

With that mindset, then, look at which language is faster to learn if you're not trying to become a developer, but to become a test automator. My vote is for Ruby.

The first time I worked with Ruby, I was tasked with the impossible: create some test automation for a homebrewed Captcha form. The in-house developers beat their heads against the wall for a while and finally threw it over the wall to me. After about a week of exploration and dirty tricks, I had an automation to get through it.

When was the last time you learned a language in a week? That's what I thought.

The ease with which I picked up Ruby blew me away. Because of that short learning curve, Ruby is a great language to use when you're trying to learn test automation at the same time.

Ruby allows you to do things a compiled language won't

Ruby has some specialized functions that other languages don't have. For example, you can make methods at runtime. This is like code writing itself—you don't have to know everything or have everything completely defined when you start out. This simplifies and speeds up your test automation script writing.

And, most importantly, if you tried to do this kind of bootstrapping with a compiled language, you'd immediately get shouted out of the auditorium. You just can't do it.

But with Ruby, since it has a lot of flexibility, you can do a lot more with it. Admittedly this kind of functionality may be for those a little more advanced. But, hey, wouldn't you like to go into a project knowing this is a possibility rather than being completely verboten?

When might you consider Ruby?

Two questions will help you decide whether to write your test automation scripts in Ruby or another language. The first is about the practitioners.

Who is going to be performing the testing? If it's the developers (not recommended, by the way), then by all means, let them write the test automation in the language they're comfortable with. If it's a separate set of testers, though, then you're a candidate for Ruby. 

And the second question is related:

Do your testers want to learn automation? If not, and if everyone is good with manual testing, then no worries; no need to learn Ruby or Python or Java or anything. Just go about your day and we'll see you on the other side—if you can keep up.

However, if your testers (and your management) are interested in speeding up the test process through automation, then it makes sense to consider Ruby. Because if you're in that boat, it's likely your testers might not have experience in learning any language.

But won't automating testing eliminate my job?

Some testers might fear that adding automation to testing would mean they aren't needed anymore. That may have been a fear way back when assembly lines were first introduced, but if testers are part of adding in automation, they'll be demonstrating that they're integral to the release calendar.

They won't be eliminated because they'll be helping the company to accelerate everything from scoping (like planning developer time for developing only) to release.

Don't delay your Ruby investigations

Seriously. You should absolutely look into it. Because when you have to learn both test automation and a language, it can be intimidating.

Cut down one of the hurdles significantly by choosing (yes, you have a choice) a language like Ruby, which has a short learning curve and is a specialized tool for exactly what you need. Your work product, and your career, will be better for it.

Keep learning

Read more articles about: App Dev & TestingTesting