How do you know if the oxygen sensor is bad?

Generally, the onboard diagnostics will tell you when you scan the computer codes.