usually people build up to it. you should think of your training in terms of weeks, months, and years, and all the things you'll be doing to build up to your goals. it's usually something i do on a whim, if i'm feeling good that day and it seems to be a good idea. usually this comes as a result of an increase in volume followed by increases in intensity. but testing a 1RM is just one small part of your overall programme.
Dave Tate says you can tell inexperienced lifters by the people who ask/talk about 1RM. It varies and depends on a lot of factors. Day, time, competition, stresses in your life, health, lots of things.