Testing light-emitting diodes, laser diodes or photodiodes