Refactor tests to use the same helper function.

This eliminates a function that was not used in some cpp files and could
cause a compiler warning.
Refs #8378