Some jurisdictions may allow you to use a borrowed motorcycle to take the riding test, but you will still need to have your own motorcycle in order to legally ride on public roads.
As for driving off after buying a motorcycle without a license from the dealer, that is generally not allowed. Dealers are required to verify that buyers have a valid motorcycle license before selling them a motorcycle. In some cases, dealers may offer temporary plates that allow you to ride the motorcycle home, but you will still need to get a license as soon as possible.