source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/types/selectors/README@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.7 KB
Line 
1A DESCRIPTION OF THE SELECTOR TEST FRAMEWORK
2
3When writing tests for selectors, I found that I wanted to have some
4standard way of working with a set of files and testing whether one or
5another of them was selected. To that end, I created a base class called
6BaseSelectorTest that does most of the heavy lifting. Of course, you can
7test your selectors any way you want, but if you want to reuse this code,
8read on.
9
10What BaseSelectorTest does is use an ant build file
11"src/etc/testcases/types/selector.xml" to copy a tree of files out of
12"src/etc/testcases/taskdefs/expected" into a "selectortest" directories.
13Then it takes a list of 12 of the files and directories in this tree, and
14applies whatever selector you pass in to each one. It passes back to your
15test a 12 character long string indicating which of the 12 files and
16directories was selected, using 'T' for selected and 'F' for not selected.
17In the Test class for your selector, you override the getInstance() method
18to create your own type of selector, and set the elements of your selector
19a variety of ways to ensure that the string of T's and F's returned when
20the selector is applied to those 12 files is correct.
21
22So, for example, DepthSelectorTest.java extends BaseSelectorTest and has
23the following code:
24
25
26 public BaseSelector getInstance() {
27 return new DepthSelector();
28 }
29
30
31 public void testSelectionBehaviour() {
32 DepthSelector s;
33 String results;
34
35
36 try {
37 makeBed();
38
39
40 s = (DepthSelector)getInstance();
41 s.setMin(20);
42 s.setMax(25);
43 results = selectionString(s);
44 assertEquals("FFFFFFFFFFFF", results);
45
46
47 s = (DepthSelector)getInstance();
48 s.setMin(0);
49 results = selectionString(s);
50 assertEquals("TTTTTTTTTTTT", results);
51
52
53 s = (DepthSelector)getInstance();
54 s.setMin(1);
55 results = selectionString(s);
56 assertEquals("FFFFFTTTTTTT", results);
57
58
59The first test says that none of the 12 files or directories will match if
60the depth range for the selector is between 20 and 25 (that would be one
61deep directory tree!). The second says that all files and directories
62match if the minimum depth is set to 0 and the maximum isn't specified. The
63third test says that if the minumum depth is 1, the first 5 entries in the
64list of 12 will not be selected and the rest will.
65
66
67You can find the 12 files and directories that are tested for selection in
68the BaseSelectorTest class. I used a fixed list so that if someone added
69new files to the src/etc/testcases/types directory it wouldn't break my
70tests:
71
72
73 protected String[] filenames = {".","asf-logo.gif.md5","asf-
74 logo.gif.bz2",
75 "asf-logo.gif.gz","copy.filterset.filtered","zip/asf-
76 logo.gif.zip",
77 "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz",
78 "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2",
79 "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"};
80
81
82If you wish to use this set of files and directories to test your selector,
83you can reuse the BaseSelectorTest with no change to it.
84
85You may find you need to alter the build file so that you get some
86variation in the files that your selector can work with. Most of the core
87selectors have required that kind of modification. If you do that, make
88sure that it doesn't alter the output strings on the other selector test,
89or if it does that you update their expected return results.
90
91You may also want to alter the set of files you look at in a particular
92selector test. Since the filelist in BaseSelectorTest is protected, you
93should be able to override it as you need to. Or you can alter the fileset
94in BaseSelectorTest itself, provided you update the test strings in all the
95other unit tests.
96
Note: See TracBrowser for help on using the repository browser.