testNG (testng.org) or Junit (http://junit.org/) is a key!
they help easily manage code like:
1) do prepare job before start any test suite (set of test cases) e.g. start appium server, or it needed to start Android Emulator or Genymotion Emulator.
2) start driver before start executing test with needed device with needed mode (fullReset or no-reset)
3) do any work after test completed
4) do any work after test suite completed e.g. stop Appium