Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

So say you have a made up flight booking application. I'm speaking on a very high level; because i'm more concerned with the design of these java objects.

We're creating tests that have these classes

  • loginTest.java: logs the user in.
  • selectFlightTest.java: selects the flight
  • searchFlightTest.java: searches for a flight
  • purchaseFlightTest.java: pick a flight

e.g. given the following scenarios:

Test booking a flight in LA, New york, Boise, Chicago, Orlando, etc.

Is it possible to design and group this particular classes into a larger utilityclass that then is a jumping point for other variations of the test? Or to be able reuse as a base class to perform other tests but with different variations?

Or is it important to just copy/paste these tests? It seems using a base java class would allow for more flexibility when like a process changes, etc.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I often put common helper code into a base class.

Mostly I do that only for "general purpose" helper code, like logging in, starting and stopping Selenium, dependency injection, and stuff like that.

For helper code related to functionality (like selecting or searching or purchasing flights), I always put that not in a base class, but in a delegate class. Often this is some form of "page object" (look it up), but I might organize it around some key concept other than pages. I might, for example, have a class that represents the airline's complete set of flights, and a class that represents searching.

Copy and paste is death. But you know that already ;-) It means that when some detail of the GUI changes, you'll have to track down all of the places it's used and change them. And you'll miss one. And someone will have fiddled with one so it's not the same any more, and you'll have to figure out why.

Any time you're tempted to copy and paste, take a moment instead to extract the common code, name it really well, and put it where people will look for it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.