blunders
blunders

Reputation: 3669

How do you write a unit test for a regex pattern?

Is it possible? Would it require a existing whitewashed and/or blacklisted datasets, or not? How would you know an exception did not exist?

Upvotes: 3

Views: 4155

Answers (2)

atconway
atconway

Reputation: 21314

You might want to look at the following link with an identical discussion that has several good solutions:

How do you unit test regular expressions?
How do you unit test regular expressions?

Upvotes: 2

Brian
Brian

Reputation: 6450

whitelists and blacklists sounds a good approach, I don't think you can "prove" it will work without exception so empirical verification is appropriate and in keeping with the spirit of unit testing

as you think up more complex/edge-case examples to test with, just add them and see if it still works, thus building a test suite in which you have ever greater levels of confidence

also, answered previously very thoroughly here

How do you unit test regular expressions?

Upvotes: 3

Related Questions