📄 readme
字号:
A DESCRIPTION OF THE SELECTOR TEST FRAMEWORKWhen writing tests for selectors, I found that I wanted to have somestandard way of working with a set of files and testing whether one oranother of them was selected. To that end, I created a base class calledBaseSelectorTest that does most of the heavy lifting. Of course, you cantest your selectors any way you want, but if you want to reuse this code,read on.What BaseSelectorTest does is use an ant build file"src/etc/testcases/types/selector.xml" to copy a tree of files out of"src/etc/testcases/taskdefs/expected" into a "selectortest" directories.Then it takes a list of 12 of the files and directories in this tree, andapplies whatever selector you pass in to each one. It passes back to yourtest a 12 character long string indicating which of the 12 files anddirectories was selected, using 'T' for selected and 'F' for not selected.In the Test class for your selector, you override the getInstance() methodto create your own type of selector, and set the elements of your selectora variety of ways to ensure that the string of T's and F's returned whenthe selector is applied to those 12 files is correct.So, for example, DepthSelectorTest.java extends BaseSelectorTest and hasthe following code: public BaseSelector getInstance() { return new DepthSelector(); } public void testSelectionBehaviour() { DepthSelector s; String results; try { makeBed(); s = (DepthSelector)getInstance(); s.setMin(20); s.setMax(25); results = selectionString(s); assertEquals("FFFFFFFFFFFF", results); s = (DepthSelector)getInstance(); s.setMin(0); results = selectionString(s); assertEquals("TTTTTTTTTTTT", results); s = (DepthSelector)getInstance(); s.setMin(1); results = selectionString(s); assertEquals("FFFFFTTTTTTT", results);The first test says that none of the 12 files or directories will match ifthe depth range for the selector is between 20 and 25 (that would be onedeep directory tree!). The second says that all files and directoriesmatch if the minimum depth is set to 0 and the maximum isn't specified. Thethird test says that if the minumum depth is 1, the first 5 entries in thelist of 12 will not be selected and the rest will.You can find the 12 files and directories that are tested for selection inthe BaseSelectorTest class. I used a fixed list so that if someone addednew files to the src/etc/testcases/types directory it wouldn't break mytests: protected String[] filenames = {".","asf-logo.gif.md5","asf- logo.gif.bz2", "asf-logo.gif.gz","copy.filterset.filtered","zip/asf- logo.gif.zip", "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz", "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2", "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"};If you wish to use this set of files and directories to test your selector,you can reuse the BaseSelectorTest with no change to it.You may find you need to alter the build file so that you get somevariation in the files that your selector can work with. Most of the coreselectors have required that kind of modification. If you do that, makesure that it doesn't alter the output strings on the other selector test,or if it does that you update their expected return results.You may also want to alter the set of files you look at in a particularselector test. Since the filelist in BaseSelectorTest is protected, youshould be able to override it as you need to. Or you can alter the filesetin BaseSelectorTest itself, provided you update the test strings in all theother unit tests.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -