Any witness may swear or affirm to tell the truth while testifying.
"Do you swear or affirm to tell the truth, the whole truth, and nothing but the truth?" You may answer "I do." or "I so swear." or "I so affirm."
Some religious traditions forbid swearing, so they affirm, rather than swear. Example: Quakers (Society of Friends)
Only in the movies do witnesses swear on the bible or "swear to god". I have worked in courts since 1972 and have never seen such a thing.