I'm new to TDD, and I'm getting a special case RegExp whether a particular method of the unit tests them , Or can I consider them as a regular work?
You should always test your regexen, like any other part of code they are the simplest tasks Which takes a string and gives a force, or gives an array of values.
Here are some suggestions on whether to think about designing unit tests for regexen. These units are not hard and fast tips for testing designs, but some guidelines are meant to shape your thinking. As always, weigh the costs of your test versus failure with the necessary time to implement them all. (I think the 'implementation' test is a simple part !: -])
The point to consider:
- Each group (bracket) is a curly Think of the brace
- Think about each one. Be sure to test for each branch as a condition.
- Think of each modifier (*, +,?) As a different path.
- (For the above side note: *, +,? And *?, +?, And ??.)
- \ d, \ s, \ w, and for their denial , Make several attempts in each category. For
- * and +, you need to test for 'any value', 'one' and 'one or more' for each.
- For important 'control' characters (for example, you are looking for regex) to see what happens to see if they appear in the wrong places it can surprise you is.
- If you have real world data, then use as much as you can.
- If you do not, both of them are simple and complex.
- To make sure the empty string is properly accepted / rejected.
- Make sure to ensure that a string of different types of characters is properly accepted or rejected.
- Ensure that the case has been properly operated insensitivity (this is the flag), this text is almost a bit more in parsing (except for the spaceship).
- If you have X, M or S options, make sure you understand what they do and test for it (
a regex Remember also:
- Verify that the data you expected is returned in the right order in the right areas.
- Verify that minor modifications Do not get back good data from.
- Verify that mixed anonymous groups and names Groups parsed correctly (e.g.,
(? & Lt; Name & gt; thing1 (thing2))
) - This behavior varies depending on the regex engine you are using - Again, do a lot of actual tests.
If you use any of the advanced features, such as non-backtracking group, make sure How do you fully understand this feature and use the above guidelines, eg Create test string, which is for each and must act against them.
Depending on your regex library implementation, which is occupied by the groups may be different. Pearl 5 has an 'open parent order' order, C #, except partially named groups and so on. After that, make sure to experiment with your taste, to ensure that with your other unit tests, integrate with regex in your own module or in the module. Especially for dirty regexen, you can find that the pattern and all the features you use are correct. If Rijks works a large (or almost all) function that is doing the procedure, then I will use the above advice on fashion inputs to test that function and not directly regex. In this way, if you decide later that Rizax is not the way to go, or you want to break it, you can capture the behavior of the razx provided without changing the interface - that is, the method which rages Invites you
Unless you really know how a regex feature is supposed to work in your regex taste, you should be able to develop good test cases for it. Just make sure that in fact, in fact, actually understand how the feature works!
Comments
Post a Comment