Vinyl test pressings are made to test the sound quality of the stampers; to make sure they are free of errors such as dropouts, and that they sound as intended, as the cutting process does have some impact on the sound. Obviously, they are pressed using the same stampers which will press the retail albums, so they will always have the same matrix codes as the retail pressing, unless the cut was rejected. Test pressings are usually pressed about one month ahead of release date and in very limited quantities, often no more than ten. They usually come with white labels or with generic pressing plant labels. Catalog numbers, dates, titles, and more may be handwritten or stamped on the labels or the inner sleeve. The text may have been written by the pressing plant, the record label, the distributor, by the original recipient, or by a collector. If the text is similar on several copies, the text is most likely written by any of the companies involved.
Test pressings are usually pressed on black vinyl, even though the retail run will be colored vinyl or a picture disc. Even though the press setup for picture discs is slightly different, pressing regular black vinyl test pressings tests the audio quality of the stampers just as well. Setting up the press for a short picture disc test pressing would mean an additional cost.  An example of this is the test pressing of the Australian Oh, The Guilt picture disc. The test pressing of the British Come As You Are picture disc is the only known Nirvana test pressing to have been done as a picture disc.
Test pressings are inspected visually and played at the pressing plant. They may be sent to the cutting engineer, the band or their management, the producer, and the record label A&R person for approval. Remaining test pressings at the pressing plant may be recycled.
Sometimes record labels, mostly smaller, independent labels, also used test pressings to presell the release to retailers by physically bringing them into the shops . Some have also been used for regular radio or press promotion, such as some copies of Love Buzz and Oh, The Guilt. In both these cases they may come with press releases or other printed information, or come in generic record label or distributor sleeves.
In theory, test pressings should exist for every vinyl release available. However, hardly any Geffen/DGC test pressings have been found. The main reason is probably that the independent labels often used them as promos and sent them around to people involved with the recording. Major labels make custom promos in large numbers, so this is not necessary for them. Most of their test pressings probably never left the pressing plants, and were instead recycled. It is also possible that several test pressings were pressed using retail labels.
As test pressings are the very first records to be made with brand new stampers, you would perhaps think that they are the best sounding records possible of that release. This may not always be the case, as they may contain test pressing noise which is caused by noise artefacts on new stampers. The first 20-50 copies from a pair of stampers during a retail press run are often discarded because it takes that many copies to get rid of the noise artefacts.  How this is practiced by the various pressing plants probably varies a lot.
To get multi-color effects on vinyl, colored vinylite pellets are mixed together when they are placed in the hopper, melted, and pushed through an extruder to form the biscuits. It is impossible to guarantee an exact result when colors are mixed this way. You usually get a swirling effect, but other effects can happen. Even so, plants will usually not make test pressings to try out the colors, because to make them you have to empty the hopper of all the existing black vinyl pellets, clean it and then put in the colors you want. This whole process is much too expensive to only make a few tests, and no pressing plant would do it for less than a minimum 500 pressing quantity, then or now. 
Some colored vinyl test pressings exist, such as the pink and white Bleach test pressings made in the USA and the UK, respectively. The pink test pressings were probably just done using the color which was available in a hopper at the time, while the white test pressings seem to have directly preceeded the retail pressing and worked as a final cleaning of the extruder. The most elaborate colored test pressing is the Hormoaning EP. In this case, the two colors seem to have come from two different hoppers and put together by hand. The test pressings of this record may have been made to test both the audio and colors at the same time.
Retail copies with odd colors may exist if the record label hoped for a particular effect. If the result was unsatisfactory, they may have decided not to release it. It is unlikely that any small indy label would do that, because they would have to absorb the cost of the manufacture. Major labels apparently do this often. 
Another possibility for odd colors is that a pressing plant keeps a variety of colored and mixed-colored vinyl samples that they can show to customers who are interested in having a colored vinyl or picture disc pressing made. The pressing plants will invariably use random stampers and labels to make these samples, basically whatever was lying around when they had some spare time and an empty hopper. 
CD test pressings aren't strictly necessary. A person reported that nobody had asked for a CD test pressing during all of his 15 years working in CD replication. The stampers can be tested on a signal analysis machine, which performs data verification system (DVS) tests and signal verification tests. The DVS tests compare the data to the image ready master bit for bit, and the signal verification tests check that the playback parameters are whithin specification. The same tests are also performed on the pressed discs sampled at various times during the pressing process, especially with long press runs. The tests are digital and fast, so nobody will have to listen to the discs to approve them.  As such, while the first disc pressed is most likely tested, it is not an advance, dedicated test pressing (unless requested by the record label which rarely happens), but pressed as a part of the retail pressing.
These discs are usually taken out of the production line just before they are to be printed, so they have no artwork. However, some plants print a custom pressing plant "sample" or "test pressing" design on the discs. These discs are often sent to the record labels where they are used internally, probably by the product manager and the sales team, or sent to distributors and other partners. They may have been used for regular promotion occasionally, but that is probably rare bacause the discs are quite limited.
There is a possibility that some sample discs may have been printed with custom promo labels and used for regular promotion. In this case more samples, or rather, unprinted discs, may have been picked from the line than usual, but not necessarily. The Canadian advance promo of From The Muddy Banks Of The Wishkah (DGCD 9687) is a strong contender. While they have a custom catalog number which is indicative of a custom pressed promo, the matrix code shows that they are the same discs as those from the retail pressing.