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.

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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