Tor Project: FAQ says:
If you want to experiment locally with your own network, or you're cut off from the Internet and want to be able to mess with Tor still, then you may want to set up your own separate Tor network.
To set up your own Tor network, you need to run your own authoritative directory servers, and your clients and relays must be configured so they know about your directory servers rather than the default public ones.
Apart from the somewhat tedious method of manually configuring a couple of directory authorities, relays and clients there are two separate tools that could help. One is Chutney, the other is Shadow.
Chutney is a tool for configuring, controlling and running tests on a testing Tor network. It requires that you have Tor and Python (2.5 or later) installed on your system. You can use Chutney to create a testing network by generating Tor configuration files (torrc) and necssary keys (for the directory authorities). Then you can let Chutney start your Tor authorities, relays and clients and wait for the network to bootstrap. Finally, you can have Chutney run tests on your network to see which things work and which do not. Chutney is typically used for running a testing network with about 10 instances of Tor. Every instance of Tor binds to one or two ports on localhost (127.0.0.1) and all Tor communication is done over the loopback interface. The Chutney README is a good starting point for getting it up and running.
Shadow is a network simulator that can run Tor through its Scallion plug-in. Although it's typically used for running load and performance tests on substantially larger Tor test networks than what's feasible with Chutney, it also makes for an excellent debugging tool since you can run completely deterministic experiments. A large Shadow network is on the size of thousands of instances of Tor, and you can run experiments out of the box using one of Shadow's several included scallion experiment configurations. Shadow can be run on any linux machine without root, and can also run on EC2 using a pre-configured image. Also, Shadow controls the time of the simulation with the effect that time-consuming tests can be done more efficiently than in an ordinary testing network. The Shadow wiki and Shadow website are good places to get started.