Labs that use animal testing do different things. Animal rights groups tend to focus on the cruelest and least practical examples, like smearing cosmetics on rabbits’ eyes to see if they become irritated (the Draize test). As you said, testing for toxicity levels as well as whether something can cause cancer or birth defects is also an important application of animal testing. It’s important to know the toxicity of drugs to determine if they’re safe for human consumption. Also, toxicity tests can be used to determine safe levels for chemicals that people are exposed to in the workplace. Testing artificial flavors and sweeteners is a relatively minor application; it’s just that it’s something we don’t need, so it’s easier for animal rights groups to focus on them.
Animal testing is also important in basic research. For example, when a new drug is developed, it is tested in animals to see if it works and whether it’s safe. This isn’t just because of the ethical concerns about testing potentially dangerous drugs in humans - in some cases, animals might be better for scientific reasons. (For example, it may be easier to study the drug’s effect in a small animal.)
This sort of research is of immense importance both in developing new drugs and in increasing our basic understanding of how the human body works and how it becomes sick. Another example might involve causing cancer in rats to better understand how cancer is caused in humans. Clearly no one would support giving cancer to humans to research how it forms.
Sometimes, animal rights groups argue that animal tests could be replaced by computers. I really don’t know how this can be done, because organisms are extremely complex and can’t be simulated well. Perhaps they assume that, because it’s possible to simulate dissecting a frog on a computer, it’s also possible to simulate animal tests. They also sometimes argue that animal tests are inaccurate and that testing should be done on humans instead. This is not true, because it is understood how animal research will relate to humans, and because animal testing often involves doing things that would be severely unethical to do to humans. To decide if it’s ethical to do these things to animals, we would also have to determine if it’s ethical to lose knowledge that could potentially avoid a lot of suffering for both humans and other animals.
I’m not sure about legal requirements for animal testing, but I do know that any facility that does animal testing has a strict code of ethics for animal research. If a scientist wants to do research in animals, they have to write an application and defend their proposal in front of an animal testing board. If the proposal would cause excessive suffering in animals or would not produce any useful knowledge, it will not be allowed. This isn’t only done when animals will be hurt or killed in research, it’s done for any testing that involves animals.
Animal testing is something that science can’t really do without for now. Perhaps we can do without new shampoos and artificial flavorings, but it’s very hard to justify not doing research on cancer or cystic fibrosis so that an animal doesn’t have to suffer. Besides, many of the animals used in testing are rats and mice that don’t live very long and probably have much less capacity to detect suffering (which, as I said, is kept to a minimum) than humans do. They are also animals that humans frequently kill with traps and poison.