As explained in a similar question, there are a few standards applicable. I'm most familiar with the European space ecosystem, so the following will be from that perspective, although I'm sure similar processes and standards exists in e.g. the USA.
The European Space Components Coordination (ESCC) coordinates standardization and qualification efforts in Europe. They also operate the European Space Component Information Exchange System (ESCIES), which includes the Qualified Parts List (QPL), an extensive list of COTS components that are qualified for use in ESA projects (and, by extension, most national space projects). If you are looking to see if components that you want to use are suitable for space applications, then the QPL would be your starting point. If your component is on that list, you do not need to have it tested.
If, on the other hand, you are a manufacturer of electrical, electronic and/or electro-mechanical (EEE) components, or you have some EEE component that is not on the list and you want to see if the components are suitable, you have to get the component tested and qualified. ESCC also maintains a (non exhaustive) list of laboratories that are capable and qualified for testing EEE components in accordance with ESCC standards.
These labs will tell you exactly what you need to provide them in order to conduct the test (how many samples, how to supply them, etc.). You can check the ESCC Specifications page and look up what the specifications are and what tests need to be conducted. For example, standard #4001 Generic Specification for Resistors Fixed Film will show you all the tests that will be done to qualify a resistor. Chart F-4 in generic document will also tell you that about 100 samples (minimum) are needed to complete the tests.
For custom PCBs things are a bit more complicated, as typically only a few are manufactured (a few engineering models and one or maybe two flight models). ESCC has an entire page dedicated to the standards applicable to PCB qualification, including design guidelines.